def test_gather_data_bad_yaml(monkeypatch): """Reads a file that contains incorrect Yaml and verifies that it rejects the file but does not raise an exception.""" def mock_join(folder_name, file_name): return "test_cleanup_report_yamls/bad_metadata.yaml" monkeypatch.setattr(os, "walk", mock_walk(["metadata.yaml"])) monkeypatch.setattr(os.path, "join", mock_join) examples = cleanup_report.gather_data("test_cleanup_report_yamls")[0] assert len(examples) == 0
def test_gather_data_multi_file(monkeypatch): """Reads metadata that contains multiple documents in one Yaml file.""" def mock_join(folder_name, file_name): return "test_cleanup_report_yamls/multi_file_metadata.yaml" monkeypatch.setattr(os, "walk", mock_walk(["metadata.yaml"])) monkeypatch.setattr(os.path, "join", mock_join) examples = cleanup_report.gather_data("test_cleanup_report_yamls")[0] assert len(examples) == 3 for example in examples: verify_example_data(example)
def test_gather_data_no_metadata(monkeypatch): """Tests that a file list with no metadata.yaml in it does not fail.""" def mock_walk_no_meta(examples_folder, topdown): folder_list = [] file_list = ["something_else.yaml", "actual_file.py"] return [("", folder_list, file_list)] monkeypatch.setattr(os, "walk", mock_walk_no_meta) examples, files = cleanup_report.gather_data("test_cleanup_report_yamls") assert len(examples) == 0 assert len(files) == 1
def test_gather_data_complex(monkeypatch, file_list): """Reads complex metadata and verifies the output.""" def mock_join(folder_name, file_name): return "test_cleanup_report_yamls/complex_metadata.yaml" monkeypatch.setattr(os, "walk", mock_walk(file_list)) monkeypatch.setattr(os.path, "join", mock_join) examples, files = cleanup_report.gather_data("test_cleanup_report_yamls") assert len(examples) == 1 verify_example_data(examples[0]) assert len(files) == len([ f for f in file_list if os.path.splitext(f)[1].lstrip('.') in cleanup_report.EXT_LOOKUP ])
def test_gather_data_capitalization(monkeypatch): """Tests that capitalization does not break reading a metadata.yaml file.""" def mock_walk_caps(examples_folder, topdown): folder_list = [] file_list = ["METAdata.yaml"] return [("", folder_list, file_list)] def mock_join(folder_name, file_name): return "test_cleanup_report_yamls/complex_metadata.yaml" monkeypatch.setattr(os, "walk", mock_walk_caps) monkeypatch.setattr(os.path, "join", mock_join) examples = cleanup_report.gather_data("test_cleanup_report_yamls")[0] assert len(examples) == 1