Skip to content

Commit 0e9adb2

Browse files
committed
Reformat using black
1 parent c0080db commit 0e9adb2

File tree

3 files changed

+45
-46
lines changed

3 files changed

+45
-46
lines changed

libzim/writer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ class Creator:
132132

133133
def __init__(self, filename, main_page, index_language, min_chunk_size):
134134
print(filename)
135-
self._creatorWrapper = libzim_wrapper.Creator(
136-
filename, main_page, index_language, min_chunk_size
137-
)
135+
self._creatorWrapper = libzim_wrapper.Creator(filename, main_page, index_language, min_chunk_size)
138136
self.filename = filename
139137
self.main_page = main_page
140138
self.language = index_language

tests/test_libzim.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ def article(article_content):
104104

105105
def test_write_article(tmpdir, article):
106106
with Creator(
107-
str(tmpdir / "test.zim"),
108-
main_page="welcome",
109-
index_language="eng",
110-
min_chunk_size=2048,
107+
str(tmpdir / "test.zim"), main_page="welcome", index_language="eng", min_chunk_size=2048,
111108
) as zim_creator:
112109
zim_creator.add_article(article)
113110
zim_creator.update_metadata(
@@ -121,21 +118,15 @@ def test_write_article(tmpdir, article):
121118

122119
def test_article_metadata(tmpdir, metadata):
123120
with Creator(
124-
str(tmpdir / "test.zim"),
125-
main_page="welcome",
126-
index_language="eng",
127-
min_chunk_size=2048,
121+
str(tmpdir / "test.zim"), main_page="welcome", index_language="eng", min_chunk_size=2048,
128122
) as zim_creator:
129123
zim_creator.update_metadata(**metadata)
130124
assert zim_creator._metadata == metadata
131125

132126

133127
def test_check_mandatory_metadata(tmpdir):
134128
with Creator(
135-
str(tmpdir / "test.zim"),
136-
main_page="welcome",
137-
index_language="eng",
138-
min_chunk_size=2048,
129+
str(tmpdir / "test.zim"), main_page="welcome", index_language="eng", min_chunk_size=2048,
139130
) as zim_creator:
140131
assert not zim_creator.mandatory_metadata_ok()
141132
zim_creator.update_metadata(

tests/test_libzim_file_reader.py

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,65 @@
1010

1111
ZIMFILES = [
1212
{
13-
'filename': str(DATA_DIR/"wikipedia_es_physics_mini.zim"),
14-
'checksum': u"99ea7a5598c6040c4f50b8ac0653b703",
15-
'namespaces': u"-AIMX",
16-
'article_count': 22027,
17-
'main_page_url': u"A/index",
13+
"filename": str(DATA_DIR / "wikipedia_es_physics_mini.zim"),
14+
"checksum": "99ea7a5598c6040c4f50b8ac0653b703",
15+
"namespaces": "-AIMX",
16+
"article_count": 22027,
17+
"main_page_url": "A/index",
1818
}
1919
]
2020

2121

22-
23-
2422
@pytest.fixture(params=ZIMFILES)
2523
def zimdata(request):
2624
return request.param
2725

26+
2827
@pytest.fixture
2928
def reader(zimdata):
30-
return File(zimdata['filename'])
29+
return File(zimdata["filename"])
3130

3231

3332
@pytest.fixture
3433
def article_data():
3534
return {
36-
'url': u"A/Albert_Einstein",
37-
'title': u"Albert Einstein",
38-
'mimetype':u"text/html",
39-
'article_id': 663,
40-
'size': 17343
35+
"url": "A/Albert_Einstein",
36+
"title": "Albert Einstein",
37+
"mimetype": "text/html",
38+
"article_id": 663,
39+
"size": 17343,
4140
}
4241

4342

4443
def test_zim_filename(reader, zimdata):
4544
for k, v in zimdata.items():
4645
assert getattr(reader, k) == v
4746

47+
4848
def test_zim_read(reader, article_data):
49-
article = reader.get_article(article_data['url'])
49+
article = reader.get_article(article_data["url"])
5050

51-
assert article.longurl == article_data['url']
52-
assert article.title == article_data['title']
53-
assert article.url == article_data['url'][2:]
54-
assert article.mimetype == article_data['mimetype']
51+
assert article.longurl == article_data["url"]
52+
assert article.title == article_data["title"]
53+
assert article.url == article_data["url"][2:]
54+
assert article.mimetype == article_data["mimetype"]
5555
assert isinstance(article.content, memoryview)
56-
assert len(article.content) == article_data['size']
56+
assert len(article.content) == article_data["size"]
57+
5758

5859
def test_content_ref_keep(reader):
5960
"""Get the memoryview on a content and loose the reference on the article.
6061
We try to load a lot of other articles to detect possible use of dandling pointer
6162
"""
62-
content =None
63+
content = None
64+
6365
def get_content():
6466
nonlocal content
65-
article = reader.get_article(u"A/Albert_Einstein")
67+
article = reader.get_article("A/Albert_Einstein")
6668
assert isinstance(article.content, memoryview)
6769
content = article.content
68-
get_content() # Now we have a content but no reference to the article.
70+
71+
get_content() # Now we have a content but no reference to the article.
6972
gc.collect()
7073
# Load a lot of content
7174
for i in range(0, reader.article_count, 2):
@@ -74,28 +77,35 @@ def get_content():
7477
c = article.content
7578
# Check everything is ok
7679
assert len(content) == 17343
77-
assert bytes(content[:100]) == b'<!DOCTYPE html>\n<html class="client-js"><head>\n <meta charset="UTF-8">\n <title>Albert Einstein</ti'
80+
assert (
81+
bytes(content[:100])
82+
== b'<!DOCTYPE html>\n<html class="client-js"><head>\n <meta charset="UTF-8">\n <title>Albert Einstein</ti'
83+
)
84+
7885

7986
def test_get_article_by_id(reader, article_data):
8087
return
81-
article = reader.get_article_by_id(article_data['article_id'])
88+
article = reader.get_article_by_id(article_data["article_id"])
89+
90+
assert article.longurl == article_data["url"]
91+
assert article.title == article_data["title"]
92+
assert article.url == article_data["url"][2:]
93+
assert article.mimetype == article_data["mimetype"]
8294

83-
assert article.longurl == article_data['url']
84-
assert article.title == article_data['title']
85-
assert article.url == article_data['url'][2:]
86-
assert article.mimetype == article_data['mimetype']
8795

8896
def test_namespace_count(reader):
8997
namespaces = reader.namespaces
9098
num_articles = sum(reader.get_namespaces_count(ns) for ns in namespaces)
9199
assert reader.article_count == num_articles
92100

101+
93102
def test_suggest(reader):
94-
results = reader.suggest(u"Einstein")
95-
assert u"A/Albert_Einstein" in list(results)
103+
results = reader.suggest("Einstein")
104+
assert "A/Albert_Einstein" in list(results)
105+
96106

97107
def test_search(reader):
98-
results = reader.search(u"Einstein")
108+
results = reader.search("Einstein")
99109
assert len(list(results)) == 10
100110

101111

0 commit comments

Comments
 (0)