def test_load_inventory_with_errors(self): location = get_test_loc('test_gen/inv4.csv') base_dir = get_temp_dir() errors, abouts = gen.load_inventory(location, base_dir) expected_errors = [ Error( CRITICAL, "Field name: 'confirmed copyright' contains illegal name characters: 0 to 9, a to z, A to Z and _." ), Error(INFO, 'Field resource is a custom field.'), Error(INFO, 'Field test is a custom field.'), Error(INFO, 'Field about_resource: Path') ] # assert [] == errors for exp, err in zip(expected_errors, errors): assert exp.severity == err.severity assert err.message.startswith(exp.message) expected = ( 'about_resource: .\n' 'name: AboutCode\n' 'version: 0.11.0\n' 'description: |\n' ' multi\n' ' line\n' # 'confirmed copyright: Copyright (c) nexB, Inc.\n' 'resource: this.ABOUT\n' 'test: This is a test\n') result = [a.dumps() for a in abouts] assert expected == result[0]
def test_load_inventory_with_mapping(self): location = get_test_loc('gen/inv4.csv') base_dir = get_test_loc('inv') license_notice_text_location = None use_mapping = True errors, abouts = gen.load_inventory(location, base_dir, license_notice_text_location, use_mapping) expected_error_messages = ['Field about_resource', 'Field test is not a supported field and is not defined in the mapping file. This field is ignored.', 'Field resource is a custom field'] assert len(errors) == 3 for e in errors: # we don't want to check the path value if e.message.startswith('Field about_resource'): continue else: assert e.message in expected_error_messages expected = [u'about_resource: .\n' u'name: AboutCode\n' u'version: 0.11.0\n' u'copyright: Copyright (c) nexB, Inc.\n' u'resource: this.ABOUT\n' u'description: |-\n' u' multi\n' u' line\n' ] result = [a.dumps(use_mapping, mapping_file=False, with_absent=False, with_empty=False) for a in abouts] assert expected == result
def test_load_inventory(self): location = get_test_loc('test_gen/inv.csv') base_dir = get_temp_dir() errors, abouts = gen.load_inventory(location, base_dir) expected_errors = [ Error(INFO, 'Field custom1 is a custom field.'), Error(INFO, 'Field about_resource: Path') ] for exp, err in zip(expected_errors, errors): assert exp.severity == err.severity assert err.message.startswith(exp.message) expected = ('''about_resource: . name: AboutCode version: 0.11.0 description: | multi line custom1: | multi line ''') result = [a.dumps() for a in abouts] assert expected == result[0]
def test_load_inventory(self): location = get_test_loc('gen/inv.csv') base_dir = get_test_loc('inv') errors, abouts = gen.load_inventory(location, base_dir) expected_error_messages = ['Field about_resource', 'Field custom1 is not a supported field and is ignored.'] # FIXME: this is not used expected_errors = [ Error(INFO, u'Field custom1 is not a supported field and is ignored.')] assert len(errors) == 2 for e in errors: # we don't want to check the path value if e.message.startswith('Field about_resource'): continue else: assert e.message in expected_error_messages expected = [u'about_resource: .\n' u'name: AboutCode\n' u'version: 0.11.0\n' u'description: |-\n' u' multi\n' u' line\n'] result = [a.dumps(use_mapping=False, mapping_file=False, with_absent=False, with_empty=False) for a in abouts] assert expected == result
def test_load_inventory_with_mapping(self): location = get_test_loc('gen/inv4.csv') base_dir = get_test_loc('inv') license_notice_text_location = None use_mapping = True errors, abouts = gen.load_inventory(location, base_dir, license_notice_text_location, use_mapping) expected_errors = [ Error( INFO, 'Field test is not a supported field and is not defined in the mapping file. This field is ignored.' ), Error(INFO, 'Field resource is a custom field') ] assert sorted(expected_errors) == sorted(errors) expected = [ u'about_resource: .\n' u'name: AboutCode\n' u'version: 0.11.0\n' u'description: |\n' u' multi\n' u' line\n' u'copyright: Copyright (c) nexB, Inc.\n' u'resource: this.ABOUT\n' ] result = [a.dumps(with_absent=False, with_empty=False) for a in abouts] assert expected == result
def test_load_inventory(self): location = get_test_loc('gen/inv.csv') base_dir = get_test_loc('inv') errors, abouts = gen.load_inventory(location, base_dir) expected_errors = [ Error(INFO, u'Field custom1 is not a supported field and is ignored.') ] assert expected_errors == errors expected = [ u'about_resource: .\n' u'name: AboutCode\n' u'version: 0.11.0\n' u'description: |\n' u' multi\n' u' line\n' ] result = [a.dumps(with_absent=False, with_empty=False) for a in abouts] assert expected == result
def test_load_inventory_with_mapping(self): location = get_test_loc('gen/inv4.csv') base_dir = get_test_loc('inv') license_notice_text_location = None use_mapping = True errors, abouts = gen.load_inventory(location, base_dir, license_notice_text_location, use_mapping) expected_error_messages = [ 'Field about_resource', 'Field test is not a supported field and is not defined in the mapping file. This field is ignored.', 'Field resource is a custom field' ] assert len(errors) == 3 for e in errors: # we don't want to check the path value if e.message.startswith('Field about_resource'): continue else: assert e.message in expected_error_messages expected = [ u'about_resource: .\n' u'name: AboutCode\n' u'version: 0.11.0\n' u'copyright: Copyright (c) nexB, Inc.\n' u'resource: this.ABOUT\n' u'description: |-\n' u' multi\n' u' line\n' ] result = [ a.dumps(use_mapping, mapping_file=False, with_absent=False, with_empty=False) for a in abouts ] assert expected == result
def test_load_inventory(self): location = get_test_loc('gen/inv.csv') base_dir = get_test_loc('inv') errors, abouts = gen.load_inventory(location, base_dir) expected_error_messages = [ 'Field about_resource', 'Field custom1 is not a supported field and is ignored.' ] # FIXME: this is not used expected_errors = [ Error(INFO, u'Field custom1 is not a supported field and is ignored.') ] assert len(errors) == 2 for e in errors: # we don't want to check the path value if e.message.startswith('Field about_resource'): continue else: assert e.message in expected_error_messages expected = [ u'about_resource: .\n' u'name: AboutCode\n' u'version: 0.11.0\n' u'description: |-\n' u' multi\n' u' line\n' ] result = [ a.dumps(use_mapping=False, mapping_file=False, with_absent=False, with_empty=False) for a in abouts ] assert expected == result