2121from collections import OrderedDict
2222import json
2323import posixpath
24+ import sys
2425import unittest
2526from unittest .case import expectedFailure
2627
4243from attributecode .util import load_csv
4344
4445
45- def check_csvs (expected , result ):
46+ def check_csv (expected , result ):
4647 """
47- Assert that the contents of two CSV files are equal.
48+ Assert that the contents of two CSV files locations `expected` and
49+ `result` are equal.
4850 """
49- expected = sorted ([d .items () for d in load_csv (expected )])
50- result = sorted ([d .items () for d in load_csv (result )])
51+ expected = sorted ([sorted ( d .items () ) for d in load_csv (expected )])
52+ result = sorted ([sorted ( d .items () ) for d in load_csv (result )])
5153 assert expected == result
5254
5355
@@ -312,8 +314,12 @@ def test_parse_rejects_non_ascii_names_and_accepts_unicode_values(self):
312314 (u'owner' , 'Matías Aguirre' )]
313315 assert expected == result
314316
317+ expected_msg = "Invalid line: 3: 'Matías: unicode field name\\ n'"
318+ if sys .version_info [0 ] < 3 : # Python 2
319+ expected_msg = "Invalid line: 3: 'Mat\\ xedas: unicode field name\\ n'"
320+
315321 expected_errors = [
316- Error (CRITICAL , "Invalid line: 3: 'Matías: unicode field name \\ n'" )]
322+ Error (CRITICAL , expected_msg )]
317323 assert expected_errors == errors
318324
319325 def test_parse_handles_blank_lines_and_spaces_in_field_names (self ):
@@ -1046,7 +1052,7 @@ def test_write_output_csv(self):
10461052 model .write_output ([a ], tmp_file , format = 'csv' )
10471053
10481054 expected = get_test_loc ('load/expected.csv' )
1049- check_csvs (expected , tmp_file )
1055+ check_csv (expected , tmp_file )
10501056
10511057 def test_write_output_json (self ):
10521058 path = 'load/this.ABOUT'
@@ -1183,17 +1189,6 @@ def test_collect_inventory_works_with_relative_paths(self):
11831189 assert expected == result1
11841190 assert expected == result2
11851191
1186- def check_csv (self , expected , result ):
1187- """
1188- Compare two CSV files at locations as lists of ordered items.
1189- """
1190- def as_items (csvfile ):
1191- return sorted ([i .items () for i in util .load_csv (csvfile )])
1192-
1193- expected = as_items (expected )
1194- result = as_items (result )
1195- assert expected == result
1196-
11971192 def test_collect_inventory_basic_from_directory (self ):
11981193 location = get_test_loc ('inventory/basic' )
11991194 result = get_temp_file ()
@@ -1205,7 +1200,7 @@ def test_collect_inventory_basic_from_directory(self):
12051200 assert expected_errors == errors
12061201
12071202 expected = get_test_loc ('inventory/basic/expected.csv' )
1208- self . check_csv (expected , result )
1203+ check_csv (expected , result )
12091204
12101205 def test_collect_inventory_with_about_resource_path_from_directory (self ):
12111206 location = get_test_loc ('inventory/basic_with_about_resource_path' )
@@ -1218,7 +1213,7 @@ def test_collect_inventory_with_about_resource_path_from_directory(self):
12181213 assert expected_errors == errors
12191214
12201215 expected = get_test_loc ('inventory/basic_with_about_resource_path/expected.csv' )
1221- self . check_csv (expected , result )
1216+ check_csv (expected , result )
12221217
12231218 def test_collect_inventory_with_no_about_resource_from_directory (self ):
12241219 location = get_test_loc ('inventory/no_about_resource_key' )
@@ -1231,13 +1226,15 @@ def test_collect_inventory_with_no_about_resource_from_directory(self):
12311226 assert expected_errors == errors
12321227
12331228 expected = get_test_loc ('inventory/no_about_resource_key/expected.csv' )
1234- self . check_csv (expected , result )
1229+ check_csv (expected , result )
12351230
1236- # FIXME: The self.check_csv is failing because there are many keys in the ABOUT files that are
1237- # not supported. Instead of removing all the non-supported keys in the output
1238- # and do the comparison, it may be best to apply the mapping to include theses keys
12391231 @expectedFailure
12401232 def test_collect_inventory_complex_from_directory (self ):
1233+ # FIXME: check_csv is failing because there are many keys in
1234+ # the ABOUT files that are not supported. Instead of removing
1235+ # all the non-supported keys in the output and do the
1236+ # comparison, it may be best to apply the mapping to include
1237+ # theses keys
12411238 location = get_test_loc ('inventory/complex' )
12421239 result = get_temp_file ()
12431240 errors , abouts = model .collect_inventory (location )
@@ -1247,7 +1244,7 @@ def test_collect_inventory_complex_from_directory(self):
12471244 assert all (e .severity == INFO for e in errors )
12481245
12491246 expected = get_test_loc ('inventory/complex/expected.csv' )
1250- self . check_csv (expected , result )
1247+ check_csv (expected , result )
12511248
12521249
12531250class GroupingsTest (unittest .TestCase ):
0 commit comments