def test_inspector_adult_easy_str_pipeline(): """ Tests whether the str version of the inspector works """ with open(ADULT_SIMPLE_PY) as file: code = file.read() inspector_result = PipelineInspector\ .on_pipeline_from_string(code)\ .add_required_inspection(MaterializeFirstOutputRows(5)) \ .add_check(NoBiasIntroducedFor(['race'])) \ .add_check(NoIllegalFeatures()) \ .execute() extracted_dag = inspector_result.dag expected_dag = get_expected_dag_adult_easy("<string-source>") compare(networkx.to_dict_of_dicts(extracted_dag), networkx.to_dict_of_dicts(expected_dag)) assert HistogramForColumns(['race']) in list( inspector_result.dag_node_to_inspection_results.values())[0] check_to_check_results = inspector_result.check_to_check_results assert check_to_check_results[NoBiasIntroducedFor( ['race'])].status == CheckStatus.SUCCESS assert check_to_check_results[ NoIllegalFeatures()].status == CheckStatus.FAILURE
def test_get_dag_as_pretty_string(): """ Tests whether the .py version of the inspector works """ extracted_dag = get_expected_dag_adult_easy("<string-source>") pretty_string = get_dag_as_pretty_string(extracted_dag) print(pretty_string)
def test_inspector_adult_easy_py_pipeline_without_inspections(): """ Tests whether the .py version of the inspector works """ inspector_result = PipelineInspector\ .on_pipeline_from_py_file(ADULT_SIMPLE_PY)\ .execute() extracted_dag = inspector_result.dag expected_dag = get_expected_dag_adult_easy(ADULT_SIMPLE_PY) compare(networkx.to_dict_of_dicts(extracted_dag), networkx.to_dict_of_dicts(expected_dag))
def test_save_fig_to_path(): """ Tests whether the .py version of the inspector works """ extracted_dag = get_expected_dag_adult_easy("<string-source>") filename = os.path.join(str(get_project_root()), "example_pipelines", "adult_simple", "adult_simple.png") save_fig_to_path(extracted_dag, filename) assert os.path.isfile(filename)
def test_pipeline_executor_nb_file(mocker): """ Tests whether the PipelineExecutor works for .ipynb files """ before_call_pandas_spy = mocker.spy(PandasBackend, 'before_call') after_call_pandas_spy = mocker.spy(PandasBackend, 'after_call') before_call_sklearn_spy = mocker.spy(SklearnBackend, 'before_call') after_call_sklearn_spy = mocker.spy(SklearnBackend, 'after_call') extracted_dag = _pipeline_executor.singleton.run( notebook_path=ADULT_SIMPLE_IPYNB).dag expected_dag = get_expected_dag_adult_easy(ADULT_SIMPLE_IPYNB, 6) compare(networkx.to_dict_of_dicts(extracted_dag), networkx.to_dict_of_dicts(expected_dag)) assert before_call_pandas_spy.call_count == 5 assert after_call_pandas_spy.call_count == 5 assert before_call_sklearn_spy.call_count == 7 assert after_call_sklearn_spy.call_count == 7
def test_pipeline_executor_py_file_without_code_reference_tracking(mocker): """ Tests whether the PipelineExecutor works for .py files """ before_call_pandas_spy = mocker.spy(PandasBackend, 'before_call') after_call_pandas_spy = mocker.spy(PandasBackend, 'after_call') before_call_sklearn_spy = mocker.spy(SklearnBackend, 'before_call') after_call_sklearn_spy = mocker.spy(SklearnBackend, 'after_call') extracted_dag = _pipeline_executor.singleton.run( python_path=ADULT_SIMPLE_PY, track_code_references=False).dag expected_dag = get_expected_dag_adult_easy(ADULT_SIMPLE_PY, with_code_references=False) compare(networkx.to_dict_of_dicts(extracted_dag), networkx.to_dict_of_dicts(expected_dag)) assert before_call_pandas_spy.call_count == 5 assert after_call_pandas_spy.call_count == 5 assert before_call_sklearn_spy.call_count == 7 assert after_call_sklearn_spy.call_count == 7