Skip to content

Commit 3185c41

Browse files
committed
Streamline atrrib generation tests
* remove unused test files * move test files under tesdata/test_attrib streamline test code Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent a57cbaf commit 3185c41

File tree

13 files changed

+36
-92
lines changed

13 files changed

+36
-92
lines changed

tests/test_attrib.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from attributecode import model
2828

2929

30-
class AttribTest(unittest.TestCase):
30+
class TemplateTest(unittest.TestCase):
3131

3232
def test_check_template_simple_valid_returns_None(self):
3333
expected = None
@@ -67,28 +67,45 @@ def test_check_template_all_builtin_templates_are_valid(self):
6767
template = tmpl.read()
6868
assert None == attrib.check_template(template)
6969

70-
def test_generate(self):
71-
test_file = get_test_loc('attrib_gen/attrib.ABOUT')
72-
errors, abouts = model.collect_inventory(test_file)
7370

74-
with open(get_test_loc('attrib_gen/test.template')) as tmpl:
75-
template = tmpl.read()
71+
class GenerateTest(unittest.TestCase):
7672

73+
def test_generate_from_collected_inventory_wih_custom_temaplte(self):
74+
test_file = get_test_loc('test_attrib/gen_simple/attrib.ABOUT')
75+
errors, abouts = model.collect_inventory(test_file)
7776
assert not errors
7877

79-
expected = (
78+
test_template = get_test_loc('test_attrib/gen_simple/test.template')
79+
with open(test_template) as tmpl:
80+
template = tmpl.read()
81+
82+
expected = (
8083
'Apache HTTP Server: 2.4.3\n'
8184
'resource: httpd-2.4.3.tar.gz\n')
8285

8386
result = attrib.generate(abouts, template)
84-
self.assertEqual(expected, result)
87+
assert expected == result
8588

86-
def test_generate_from_file_with_default_template(self):
87-
test_file = get_test_loc('attrib_gen/attrib.ABOUT')
88-
_errors, abouts = model.collect_inventory(test_file)
89+
def test_generate_with_default_template(self):
90+
test_file = get_test_loc('test_attrib/gen_default_template/attrib.ABOUT')
91+
errors, abouts = model.collect_inventory(test_file)
92+
assert not errors
8993
result = attrib.generate_from_file(abouts)
90-
with open(get_test_loc('attrib_gen/expected_default_attrib.html')) as exp:
94+
95+
expected_file = get_test_loc(
96+
'test_attrib/gen_default_template/expected_default_attrib.html')
97+
with open(expected_file) as exp:
9198
expected = exp.read()
99+
92100
# strip the timestamp: the timestamp is wrapped in italic block
93-
self.assertEqual([x.rstrip() for x in expected.splitlines()],
94-
[x.rstrip() for x in result.splitlines() if not '<i>' in x])
101+
result = remove_timestamp(result)
102+
expected = remove_timestamp(expected)
103+
assert expected == result
104+
105+
106+
def remove_timestamp(html_text):
107+
"""
108+
Return the `html_text` generated attribution stripped from timestamps: the
109+
timestamp is wrapped in italic block in the default template.
110+
"""
111+
return '\n'.join(x for x in html_text.splitlines() if not '<i>' in x)

tests/testdata/attrib_gen/license_text.ABOUT

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/testdata/attrib_gen/license_text.LICENSE

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/testdata/attrib_gen/missing_notice_license_files.ABOUT

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/testdata/attrib_gen/no_text_file_field.ABOUT

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/testdata/attrib_gen/notice_text.NOTICE

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/testdata/attrib_gen/test-about-code-tempfile

Lines changed: 0 additions & 53 deletions
This file was deleted.

tests/testdata/attrib_gen/attrib.ABOUT renamed to tests/testdata/test_attrib/gen_default_template/attrib.ABOUT

File renamed without changes.

tests/testdata/attrib_gen/expected_default_attrib.html renamed to tests/testdata/test_attrib/gen_default_template/expected_default_attrib.html

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mock archive document in attrib.ABOUT

0 commit comments

Comments
 (0)