def test_plot_filter_dataframe_for_plotting_gpu_and_cpu_fail( capsys, cli_runner, tmpdir, data ): """ Tests the error when gpu and cpu are set to false. """ with tmpdir.as_cwd(): input_df = pd.read_csv(data["testcsv.csv"]) expected_output = "ERROR CPU and GPU not set. Nothing to plot. Exiting.\n" with pytest.raises(SystemExit) as error: plot.filter_dataframe_for_plotting( df=input_df, host_name=(), module_name=(), gpu=False, cpu=False ) out, _ = capsys.readouterr() assert out == expected_output assert error.type == SystemExit assert error.value.code == 1
def test_plot_filter_empty_dataframe_error(cli_runner, capsys, tmpdir, data): """Assert that we exit when given an empty DataFrame through a specific filter combination. """ with tmpdir.as_cwd(): df = pd.read_csv(data["testcsv.csv"]) df = df[(~df["gpu"]) & (df["host"] == "draco")] with pytest.raises(SystemExit) as error: plot.filter_dataframe_for_plotting( df=df, host_name=("draco",), module_name=(), gpu=True, cpu=False ) expected_output = ( "Plotting GPU data only.\n" "ERROR Your filtering led to an empty dataset. Exiting.\n" ) out, _ = capsys.readouterr() assert out == expected_output assert error.type == SystemExit assert error.value.code == 1
def test_plot_filter_dataframe_for_plotting_host_name( cli_runner, tmpdir, data, host_name ): """ Checks whether the host names are filtered correctly in the filtering function. """ with tmpdir.as_cwd(): expected_df = pd.read_csv(data["testcsv.csv"]) expected_df = expected_df[expected_df["host"].str.contains(host_name)] input_df = pd.read_csv(data["testcsv.csv"]) real_df = plot.filter_dataframe_for_plotting( df=input_df, host_name=(host_name,), module_name=(), gpu=True, cpu=True ) assert_frame_equal(expected_df, real_df)
def test_plot_filter_dataframe_for_plotting_gpu_and_cpu( cli_runner, tmpdir, data, gpu, cpu ): """ Checks whether the cpu and gpu filtering works properly. """ with tmpdir.as_cwd(): input_df = pd.read_csv(data["testcsv.csv"]) if gpu and not cpu: input_df = input_df[input_df.gpu] elif not gpu and cpu: input_df = input_df[~input_df.gpu] elif not gpu and not cpu: input_df = pd.read_csv(data["empty_df.csv"]) real_df = plot.filter_dataframe_for_plotting( df=input_df, host_name=(), module_name=(), gpu=gpu, cpu=cpu ) # here we compare the dataframes for any differences assert_frame_equal(input_df, real_df)