|
27 | 27 | from attributecode import model |
28 | 28 |
|
29 | 29 |
|
30 | | -class AttribTest(unittest.TestCase): |
| 30 | +class TemplateTest(unittest.TestCase): |
31 | 31 |
|
32 | 32 | def test_check_template_simple_valid_returns_None(self): |
33 | 33 | expected = None |
@@ -67,28 +67,45 @@ def test_check_template_all_builtin_templates_are_valid(self): |
67 | 67 | template = tmpl.read() |
68 | 68 | assert None == attrib.check_template(template) |
69 | 69 |
|
70 | | - def test_generate(self): |
71 | | - test_file = get_test_loc('attrib_gen/attrib.ABOUT') |
72 | | - errors, abouts = model.collect_inventory(test_file) |
73 | 70 |
|
74 | | - with open(get_test_loc('attrib_gen/test.template')) as tmpl: |
75 | | - template = tmpl.read() |
| 71 | +class GenerateTest(unittest.TestCase): |
76 | 72 |
|
| 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) |
77 | 76 | assert not errors |
78 | 77 |
|
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 = ( |
80 | 83 | 'Apache HTTP Server: 2.4.3\n' |
81 | 84 | 'resource: httpd-2.4.3.tar.gz\n') |
82 | 85 |
|
83 | 86 | result = attrib.generate(abouts, template) |
84 | | - self.assertEqual(expected, result) |
| 87 | + assert expected == result |
85 | 88 |
|
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 |
89 | 93 | 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: |
91 | 98 | expected = exp.read() |
| 99 | + |
92 | 100 | # 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) |
0 commit comments