Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for new feature #301

Merged
merged 10 commits into from
Aug 6, 2018
5 changes: 5 additions & 0 deletions buku.py
Original file line number Diff line number Diff line change
Expand Up @@ -4071,6 +4071,11 @@ def to_temp_file_content(url, title_in, tags_in, desc):
-------
str
Lines as newline separated string.

Raises
------
AttributeError
when tags_in is None.
"""

strings = [('# Lines beginning with "#" will be stripped.\n'
Expand Down
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@
license='GPLv3',
platforms=['any'],
py_modules=['buku'],
install_requires=['certifi', 'urllib3>=1.13.1', 'beautifulsoup4>=4.4.1', 'cryptography>=1.2.3'],
install_requires=[
'beautifulsoup4>=4.4.1',
'certifi',
'cryptography>=1.2.3',
'urllib3>=1.13.1',
'html5lib>=1.0.1',
],
packages=find_packages(exclude=['tests']),
include_package_data=True,
entry_points={
Expand Down
66 changes: 0 additions & 66 deletions tests/test_BukuHTMLParser.py

This file was deleted.

122 changes: 54 additions & 68 deletions tests/test_buku.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ def test_is_ignored_mime(url, exp_res):
assert exp_res == buku.is_ignored_mime(url)


def test_get_page_title():
"""test func."""
resp = mock.Mock()
parser = mock.Mock()
parser.parsed_title = 'doubled whitespace'
with mock.patch('buku.BukuHTMLParser', return_value=parser):
import buku
res = buku.get_page_title(resp)
assert res == 'doubled whitespace'


def test_gen_headers():
"""test func."""
import buku
Expand All @@ -78,18 +67,10 @@ def test_gen_headers():
@pytest.mark.parametrize('m_myproxy', [None, mock.Mock()])
def test_get_PoolManager(m_myproxy):
"""test func."""
with mock.patch('buku.urllib3') as m_ul3:
with mock.patch('buku.urllib3'):
import buku
buku.myproxy = m_myproxy
res = buku.get_PoolManager()
if m_myproxy:
m_ul3.ProxyManager.assert_called_once_with(
m_myproxy, num_pools=1, timeout=15, headers=buku.myheaders)
assert res == m_ul3.ProxyManager.return_value
else:
m_ul3.PoolManager.assert_called_once_with(
num_pools=1, timeout=15, headers=buku.myheaders)
assert res == m_ul3.PoolManager.return_value
assert buku.get_PoolManager()


@pytest.mark.parametrize(
Expand Down Expand Up @@ -397,50 +378,41 @@ def test_is_editor_valid(editor, exp_res):
product(
[None, 'example.com'],
[None, '', 'title'],
['', 'tag1,tag2', ',tag1,tag2,'],
[None, '', 'description'],
[None, '', '-', 'tag1,tag2', ',tag1,tag2,', ',,,,,'],
[None, '', '-', 'description'],
)
)
def test_to_temp_file_content(url, title_in, tags_in, desc):
"""test func."""
import buku
res = buku.to_temp_file_content(url, title_in, tags_in, desc)
lines = [
'# Lines beginning with "#" will be stripped.',
'# Add URL in next line (single line).',
'# Add TITLE in next line (single line). Leave blank to web fetch, "-" for no title.',
'# Add comma-separated TAGS in next line (single line).',
'# Add COMMENTS in next line(s).',
]
idx_offset = 0
# url
if url is not None:
lines.insert(2, url)
idx_offset += 1
if desc is None:
desc_text = '\n'
elif desc == '':
desc_text = '-'
else:
desc_text = desc
if title_in is None:
title_in = ''
title_text = ''
elif title_in == '':
title_in = '-'
else:
pass

# title
lines.insert(idx_offset + 3, title_in)
idx_offset += 1

# tags
lines.insert(idx_offset + 4, tags_in.strip(buku.DELIM))
idx_offset += 1

# description
if desc is not None and desc != '':
pass
title_text = '-'
else:
desc = ''
lines.insert(idx_offset + 5, desc)

for idx, res_line in enumerate(res.splitlines()):
assert lines[idx] == res_line
title_text = title_in
if tags_in is None:
with pytest.raises(AttributeError):
res = buku.to_temp_file_content(url, title_in, tags_in, desc)
return
res = buku.to_temp_file_content(url, title_in, tags_in, desc)
lines = """# Lines beginning with "#" will be stripped.
# Add URL in next line (single line).{}
# Add TITLE in next line (single line). Leave blank to web fetch, "-" for no title.{}
# Add comma-separated TAGS in next line (single line).{}
# Add COMMENTS in next line(s). Leave blank to web fetch, "-" for no comments.{}""".format(
''.join(['\n', url]) if url is not None else '',
''.join(['\n', title_text]),
''.join(['\n', ','.join([x for x in tags_in.split(',') if x])]) if tags_in else '\n',
''.join(['\n', desc_text])
)
assert res == lines


@pytest.mark.parametrize(
Expand Down Expand Up @@ -550,15 +522,20 @@ def test_sigint_handler(capsys):
@pytest.mark.parametrize(
'url, exp_res',
[
['http://example.com.', ('', 0, 1)],
['http://example.com', ('Example Domain', 0, 0)],
['http://example.com/page1.txt', (('', 1, 0))],
['about:new_page', (('', 0, 1))],
['chrome://version/', (('', 0, 1))],
['chrome://version/', (('', 0, 1))],
['http://example.com.', (None, None, None, 0, 1)],
['http://example.com', ('Example Domain', None, None, 0, 0)],
['http://example.com/page1.txt', (('', '', '', 1, 0))],
['about:new_page', ((None, None, None, 0, 1))],
['chrome://version/', ((None, None, None, 0, 1))],
['chrome://version/', ((None, None, None, 0, 1))],
[
'http://4pda.ru/forum/index.php?showtopic=182463&st=1640#entry6044923',
('Samsung GT-I5800 Galaxy 580 - Обсуждение - 4PDA', 0, 0)
(
'Samsung GT-I5800 Galaxy 580 - Обсуждение - 4PDA',
'Samsung GT-I5800 Galaxy 580 - Обсуждение - 4PDA',
'Samsung GT-I5800 Galaxy 580 - Обсуждение - 4PDA',
0, 0
)
],
[
'https://www.google.ru/search?'
Expand All @@ -567,18 +544,25 @@ def test_sigint_handler(capsys):
'gs_l=serp.3..33i21.28976559.28977886.0.'
'28978017.6.6.0.0.0.0.167.668.0j5.5.0....0...1c.1.64.'
'serp..1.2.311.06cSKPTLo18',
('xkbcomp alt gr', 0, 0)
('xkbcomp alt gr', None, None, 0, 0)
],
[
'http://www.vim.org/scripts/script.php?script_id=4641',
(
'mlessnau_case - "in-case" selection, deletion and substitution '
'for underscore, camel, mixed case : vim online', 0, 0
'for underscore, camel, mixed case : vim online',
None, None, 0, 0
)
],
[
'http://www.kadrof.ru/cat_exchange.shtml',
('Все биржи фриланса и удаленной работы - больше 110 сайтов | Kadrof.ru', 0, 0)
(
'Все биржи фриланса и удаленной работы - больше 110 сайтов | Kadrof.ru',
'Здесь собраны самые популярные биржи удаленной работы и фриланса для новичков и опытных специалистов. '
'Более 110 ресурсов по видам:',
'биржи удаленной работы,биржи фриланс',
0, 0
)
],
]
)
Expand All @@ -590,7 +574,9 @@ def test_network_handler_with_url(url, exp_res):
buku.myproxy = None
res = buku.network_handler(url)
if urlparse(url).netloc == 'www.google.ru':
res = (res[0].split(" - ")[0], res[1], res[2])
temp_res = [res[0].split(" - ")[0], ]
temp_res.extend(res[1:])
res = tuple(temp_res)
assert res == exp_res


Expand Down
5 changes: 2 additions & 3 deletions tests/test_bukuDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,6 @@ def refreshdb_fixture():
os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH


# @pytest.mark.slowtest
@pytest.mark.parametrize(
"title_in, exp_res",
[
Expand All @@ -682,7 +681,7 @@ def refreshdb_fixture():
)
def test_refreshdb(refreshdb_fixture, title_in, exp_res):
bdb = refreshdb_fixture
args = ["https://example.com"]
args = ["http://example.com"]
if title_in:
args.append(title_in)
bdb.add_rec(*args)
Expand Down Expand Up @@ -1008,7 +1007,7 @@ def test_add_rec_add_invalid_url(caplog, url):
],
[
{'url': 'http://example.com', 'tags_in': 'tag1'},
('http://example.com', 'Example Domain', ',tag1', '', 0),
('http://example.com', 'Example Domain', ',tag1,', '', 0),
],
[
{'url': 'http://example.com', 'tags_in': ',tag1'},
Expand Down