def test_process(files): files = files["resources"] file_1 = files["file_1"] file_2 = files["file_2"] tfm = Transformer([], SingleJsonRetriever()) tfm.files = [file_1, file_2] expected_result = [{ "data": [ { "value": 101, "xaxis": 1, "file": file_1 }, { "value": 102, "xaxis": 1, "file": file_1 }, { "value": 103, "xaxis": 1, "file": file_1 }, { "value": 201, "xaxis": 2, "file": file_2 }, { "value": 202, "xaxis": 2, "file": file_2 }, { "value": 203, "xaxis": 2, "file": file_2 }, ], "subtest": "browserScripts.timings.firstPaint", "name": "group_1", }] actual_result = tfm.process("group_1") assert actual_result == expected_result
def test_jsonschema_valitate_failure(files): class BadTransformer: def transform(self, data): return {"bad data": "bad data"} def merge(self, sde): return {"bad data": "bad data"} files = files["resources"] file_1 = files["file_1"] file_2 = files["file_2"] tfm = Transformer([], BadTransformer(), logger=metadata, prefix=prefix) tfm.files = [file_1, file_2] with pytest.raises(ValidationError): tfm.process("name")
def test_init_failure(): class TempClass(object): def temp_fun(): return 1 with pytest.raises(NotebookInvalidTransformError): Transformer(custom_transformer=TempClass())
def test_open_data(data, files): tfm = Transformer(logger=metadata, prefix=prefix) files = files["resources"] json_1 = files["file_1"] json_2 = files["file_2"] txt_3 = files["file_3"] # If a json file is open. assert data["data_1"] == tfm.open_data(json_1) assert data["data_2"] == tfm.open_data(json_2) # If an other type file is open. assert [str(data["data_3"])] == tfm.open_data(txt_3) # Test failure with pytest.raises(Exception): tfm.open_data("fail")
def test_process(ptnbs, files): # Temporary resource files. files, _, output = files file_1 = files["file_1"] file_2 = files["file_2"] # Create expected output. expected_output = [{ "data": [ { "value": 101, "xaxis": 1, "file": file_1 }, { "value": 102, "xaxis": 1, "file": file_1 }, { "value": 103, "xaxis": 1, "file": file_1 }, { "value": 201, "xaxis": 2, "file": file_2 }, { "value": 202, "xaxis": 2, "file": file_2 }, { "value": 203, "xaxis": 2, "file": file_2 }, ], "name": "group_1", "subtest": "browserScripts.timings.firstPaint", }] ptnb = ptnbs["ptnb_str"] # Set a custom transformer. ptnb.transformer = Transformer([], SingleJsonRetriever()) # Create expected result. expected_result = { "data": expected_output, "file-output": output, } # Check return value. actual_result = ptnb.process() assert actual_result == expected_result # Check output file. with pathlib.Path(output).open() as f: actual_output = json.load(f) assert expected_output == actual_output
def test_files_setter_failure(): tfm = Transformer(logger=metadata, prefix=prefix) tfm.files = "fail" assert not tfm.files
def test_files_setter(files): files = files["resources"] files = list(files.values()) tfm = Transformer(logger=metadata, prefix=prefix) tfm.files = files assert files == tfm.files
def test_files_getter(files): files = files["resources"] assert files == Transformer(files, logger=metadata, prefix=prefix).files
def test_files_setter_failure(): tfm = Transformer() tfm.files = "fail" assert not tfm.files
def test_files_setter(files): files, _, _ = files files = list(files.values()) tfm = Transformer() tfm.files = files assert files == tfm.files
def test_files_getter(files): files, _, _ = files assert files == Transformer(files).files