def test_write_output_csv_with_multiple_files(self): path = 'test_model/multiple_files.ABOUT' test_file = get_test_loc(path) abouts = model.About(location=test_file, about_file_path=path) result = get_temp_file() model.write_output([abouts], result, format='csv') expected = get_test_loc('test_model/multiple_files_expected.csv') check_csv(expected, result)
def test_write_output_json(self): path = 'test_model/this.ABOUT' test_file = get_test_loc(path) abouts = model.About(location=test_file, about_file_path=path) result = get_temp_file() model.write_output([abouts], result, format='json') expected = get_test_loc('test_model/expected.json') check_json(expected, result)
def test_collect_inventory_does_not_convert_lf_to_crlf_from_directory( self): location = get_test_loc('test_model/crlf/about.ABOUT') result = get_temp_file() errors, abouts = model.collect_inventory(location) errors2 = model.write_output(abouts, result, format='csv') errors.extend(errors2) assert all(e.severity == INFO for e in errors) expected = get_test_loc('test_model/crlf/expected.csv') check_csv(expected, result, fix_cell_linesep=True, regen=False)
def test_collect_inventory_complex_from_directory(self): location = get_test_loc('test_model/inventory/complex') result = get_temp_file() errors, abouts = model.collect_inventory(location) model.write_output(abouts, result, format='csv') assert all(e.severity == INFO for e in errors) expected = get_test_loc('test_model/inventory/complex/expected.csv') check_csv(expected, result, fix_cell_linesep=True, regen=False)
def test_collect_inventory_with_no_about_resource_from_directory(self): location = get_test_loc('test_model/inventory/no_about_resource_key') result = get_temp_file() errors, abouts = model.collect_inventory(location) model.write_output(abouts, result, format='csv') expected_errors = [ Error(CRITICAL, 'about/about.ABOUT: Field about_resource is required') ] assert expected_errors == errors
def test_collect_inventory_basic_from_directory(self): location = get_test_loc('test_model/inventory/basic') result = get_temp_file() errors, abouts = model.collect_inventory(location) model.write_output(abouts, result, format='csv') expected_errors = [] assert expected_errors == errors expected = get_test_loc('test_model/inventory/basic/expected.csv') check_csv(expected, result)
def test_load_dump_is_idempotent(self): test_file = get_test_loc('test_model/this.ABOUT') a = model.About() a.load(test_file) dumped_file = get_temp_file('that.ABOUT') a.dump(dumped_file) expected = get_unicode_content(test_file).splitlines() result = get_unicode_content(dumped_file).splitlines() # Ignore comment and empty line filtered_result = [] for line in result: if not line.startswith('#') and not line == '': filtered_result.append(line) assert expected == filtered_result
def test_lic_key_name_sync(self): test_file = get_test_loc( 'test_attrib/gen_license_key_name_check/test.ABOUT') expected = get_test_loc( 'test_attrib/gen_license_key_name_check/expected/expected.html') template_loc = get_test_loc( 'test_attrib/gen_license_key_name_check/custom.template') output_file = get_temp_file() errors, abouts = model.collect_inventory(test_file) attrib.generate_and_save(abouts, output_file, template_loc) with open(output_file) as of: f1 = '\n'.join(of.readlines(False)) with open(expected) as ef: f2 = '\n'.join(ef.readlines(False)) assert f1 == f2
def test_report_errors_can_write_to_logfile(): errors = [ Error(CRITICAL, 'msg1'), Error(ERROR, 'msg2'), Error(INFO, 'msg3'), Error(WARNING, 'msg4'), Error(DEBUG, 'msg4'), Error(NOTSET, 'msg4'), Error(WARNING, 'msg4'), ] result_file = get_temp_file() _ec = cmd.report_errors(errors, quiet=False, verbose=True, log_file_loc=result_file) with io.open(result_file, 'r', encoding='utf-8') as rf: result = rf.read() expected = [ 'Command completed with 3 errors or warnings.', 'CRITICAL: msg1', 'ERROR: msg2', 'INFO: msg3', 'WARNING: msg4', 'DEBUG: msg4', 'NOTSET: msg4' ] assert expected == result.splitlines(False)
def test_about_transform_command_can_run_minimally_without_error(): test_file = get_test_loc('test_cmd/transform.csv') result = get_temp_file('file_name.csv') run_about_command_test_click(['transform', test_file, result])
def test_about_attrib_command_can_run_minimally_without_error(): test_dir = get_test_loc('test_cmd/repository-mini') result = get_temp_file() run_about_command_test_click(['attrib', test_dir, result])