3434
3535class GenTest (unittest .TestCase ):
3636 def test_check_duplicated_columns (self ):
37- test_file = get_test_loc ('gen /dup_keys.csv' )
37+ test_file = get_test_loc ('test_gen /dup_keys.csv' )
3838 expected = [Error (ERROR , u'Duplicated column name(s): copyright with copyright\n Please correct the input and re-run.' )]
3939 result = gen .check_duplicated_columns (test_file )
4040 assert expected == result
4141
4242 def test_check_duplicated_columns_handles_lower_upper_case (self ):
43- test_file = get_test_loc ('gen /dup_keys_with_diff_case.csv' )
43+ test_file = get_test_loc ('test_gen /dup_keys_with_diff_case.csv' )
4444 expected = [Error (ERROR , u'Duplicated column name(s): copyright with Copyright\n Please correct the input and re-run.' )]
4545 result = gen .check_duplicated_columns (test_file )
4646 assert expected == result
@@ -55,50 +55,44 @@ def test_check_duplicated_about_file_path(self):
5555 assert expected == result
5656
5757 def test_load_inventory (self ):
58- location = get_test_loc ('gen /inv.csv' )
58+ location = get_test_loc ('test_gen /inv.csv' )
5959 base_dir = get_test_loc ('inv' )
6060 errors , abouts = gen .load_inventory (location , base_dir )
6161
62- expected_error_messages = ['Field about_resource' ,
63- 'Field custom1 is not a supported field and is ignored.' ]
64- # FIXME: this is not used
6562 expected_errors = [
66- Error (INFO , u 'Field custom1 is not a supported field and is ignored.' )]
67- assert len ( errors ) == 2
68- for e in errors :
69- # we don't want to check the path value
70- if e . message . startswith ( 'Field about_resource' ):
71- continue
72- else :
73- assert e . message in expected_error_messages
74-
75- expected = [ u'about_resource: . \n '
76- u'name: AboutCode \n '
77- u'version: 0.11.0 \n '
78- u'description: |- \n '
79- u ' multi \n '
80- u' line \n ' ]
63+ Error (INFO , 'Field custom1 is not a supported field and is ignored.' ),
64+ Error ( INFO , 'Field about_resource: Path' )
65+ ]
66+ for exp , err in zip ( expected_errors , errors ):
67+ assert exp . severity == err . severity
68+ assert err . message . startswith ( exp . message )
69+
70+ expected = (
71+ 'about_resource: . \n '
72+ 'name: AboutCode \n '
73+ 'version: 0.11.0 \n '
74+ 'description: |- \n '
75+ ' multi \n '
76+ ' line \n '
77+ )
8178 result = [a .dumps (mapping_file = False , with_absent = False , with_empty = False )
8279 for a in abouts ]
83- assert expected == result
80+ assert expected == result [ 0 ]
8481
8582 def test_load_inventory_with_mapping (self ):
86- location = get_test_loc ('gen/inv4.csv' )
87- base_dir = get_test_loc ('inv' )
88- errors , abouts = gen .load_inventory (
89- location , base_dir , mapping_file = DEFAULT_MAPPING )
90- expected_error_messages = [
91- 'Field about_resource' ,
92- 'Field test is not a supported field and is not defined in the mapping file. This field is ignored.' ,
93- 'Field resource is a custom field' ]
94-
95- assert len (errors ) == 3
96- for e in errors :
97- # we don't want to check the path value
98- if e .message .startswith ('Field about_resource' ):
99- continue
100- else :
101- assert e .message in expected_error_messages
83+ location = get_test_loc ('test_gen/inv4.csv' )
84+ base_dir = get_test_loc ('test_gen/inv' )
85+ errors , abouts = gen .load_inventory (location , base_dir , mapping_file = DEFAULT_MAPPING )
86+
87+ expected_errors = [
88+ Error (INFO , 'Field resource is a custom field' ),
89+ Error (INFO , 'Field test is not a supported field and is not defined in the mapping file. This field is ignored.' ),
90+ Error (INFO , 'Field about_resource: Path ' )
91+ ]
92+
93+ for exp , err in zip (expected_errors , errors ):
94+ assert exp .severity == err .severity
95+ assert err .message .startswith (exp .message )
10296
10397 expected = (
10498 'about_resource: .\n '
@@ -114,7 +108,7 @@ def test_load_inventory_with_mapping(self):
114108 assert expected == result [0 ]
115109
116110 def test_generation_dir_endswith_space (self ):
117- location = get_test_loc ('inventory/complex/about_file_path_dir_endswith_space.csv' )
111+ location = get_test_loc ('test_gen/ inventory/complex/about_file_path_dir_endswith_space.csv' )
118112 base_dir = get_temp_dir ()
119113 errors , _abouts = gen .generate (location , base_dir )
120114 expected_errors_msg1 = 'contains directory name ends with spaces which is not allowed. Generation skipped.'
@@ -125,15 +119,15 @@ def test_generation_dir_endswith_space(self):
125119 assert expected_errors_msg2 in errors [0 ].message or expected_errors_msg2 in errors [1 ].message
126120
127121 def test_generation_with_no_about_resource (self ):
128- location = get_test_loc ('gen /inv2.csv' )
122+ location = get_test_loc ('test_gen /inv2.csv' )
129123 base_dir = get_temp_dir ()
130124 errors , abouts = gen .generate (location , base_dir )
131125 expected = OrderedDict ([(u'.' , None )])
132126 assert abouts [0 ].about_resource .value == expected
133127 assert len (errors ) == 1
134128
135129 def test_generation_with_no_about_resource_reference (self ):
136- location = get_test_loc ('gen /inv3.csv' )
130+ location = get_test_loc ('test_gen /inv3.csv' )
137131 base_dir = get_temp_dir ()
138132
139133 errors , abouts = gen .generate (location , base_dir )
@@ -145,7 +139,7 @@ def test_generation_with_no_about_resource_reference(self):
145139 assert msg in errors [0 ].message
146140
147141 def test_generation_with_no_about_resource_reference_no_resource_validation (self ):
148- location = get_test_loc ('gen /inv3.csv' )
142+ location = get_test_loc ('test_gen /inv3.csv' )
149143 base_dir = get_temp_dir ()
150144
151145 errors , abouts = gen .generate (location , base_dir )
@@ -155,7 +149,7 @@ def test_generation_with_no_about_resource_reference_no_resource_validation(self
155149 assert len (errors ) == 1
156150
157151 def test_generate (self ):
158- location = get_test_loc ('gen /inv.csv' )
152+ location = get_test_loc ('test_gen /inv.csv' )
159153 base_dir = get_temp_dir ()
160154
161155 errors , abouts = gen .generate (location , base_dir )
@@ -177,7 +171,7 @@ def test_generate(self):
177171 assert expected == in_mem_result
178172
179173 def test_generate_not_overwrite_original_license_file (self ):
180- location = get_test_loc ('gen /inv5.csv' )
174+ location = get_test_loc ('test_gen /inv5.csv' )
181175 base_dir = get_temp_dir ()
182176 license_notice_text_location = None
183177 fetch_license = ['url' , 'lic_key' ]
0 commit comments