From 07fa3e16deee41a0fe4f2fd6d1d8387a607fdcd4 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 5 Mar 2024 22:42:59 +0100 Subject: [PATCH] reimplement tests --- .github/workflows/ci.yml | 85 ++----------------- ...licit-columns.yaml => config-default.yaml} | 8 +- tests/test-dask-local.yaml | 10 --- tests/test-data-access.py | 25 ++++++ tests/test-default.yaml | 10 --- tests/test-executors.py | 31 +++++++ tests/test-futures.yaml | 10 --- tests/test-processing.py | 73 ++++++++++++++++ tests/test-read-by-column.yaml | 10 --- tests/test-read-by-file.yaml | 10 --- tests/test-read-from-dir.yaml | 10 --- tests/utils.py | 13 +++ 12 files changed, 153 insertions(+), 142 deletions(-) rename tests/{test-explicit-columns.yaml => config-default.yaml} (81%) delete mode 100644 tests/test-dask-local.yaml create mode 100644 tests/test-data-access.py delete mode 100644 tests/test-default.yaml create mode 100644 tests/test-executors.py delete mode 100644 tests/test-futures.yaml create mode 100644 tests/test-processing.py delete mode 100644 tests/test-read-by-column.yaml delete mode 100644 tests/test-read-by-file.yaml delete mode 100644 tests/test-read-from-dir.yaml create mode 100644 tests/utils.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07fc151..04ff0b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: - master jobs: - default: + test-data-access: runs-on: ubuntu-latest steps: - name: Checkout repository @@ -20,10 +20,10 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt - - name: Default test - run: python3 af_benchmark/benchmark.py tests/test-default.yaml + - name: Run data access tests + run: python3 tests/test-data-access.py - read-from-dir: + test-executors: runs-on: ubuntu-latest steps: - name: Checkout repository @@ -38,9 +38,9 @@ jobs: run: pip install -r requirements.txt - name: - run: python3 af_benchmark/benchmark.py tests/test-read-from-dir.yaml + run: python3 tests/test-executors.py - futures-executor: + test-processing: runs-on: ubuntu-latest steps: - name: Checkout repository @@ -54,75 +54,6 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt - - name: Test futures executor - run: python3 af_benchmark/benchmark.py tests/test-futures.yaml - - dask-local-executor: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - - name: Install dependencies - run: pip install -r requirements.txt - - - name: Test Dask executor (local) - run: python3 af_benchmark/benchmark.py tests/test-dask-local.yaml - - explicit-columns: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - - name: Install dependencies - run: pip install -r requirements.txt - - - name: Test explicit list of columns - run: python3 af_benchmark/benchmark.py tests/test-explicit-columns.yaml - - read-by-file: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - - name: Install dependencies - run: pip install -r requirements.txt - - - name: Test parallelization over files - run: python3 af_benchmark/benchmark.py tests/test-read-by-file.yaml - - read-by-column: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - - name: Install dependencies - run: pip install -r requirements.txt - - - name: Test parallelization over columns - run: python3 af_benchmark/benchmark.py tests/test-read-by-column.yaml - + - name: Test processing + run: tests/test-processing.py diff --git a/tests/test-explicit-columns.yaml b/tests/config-default.yaml similarity index 81% rename from tests/test-explicit-columns.yaml rename to tests/config-default.yaml index cbfb12e..9e36b99 100644 --- a/tests/test-explicit-columns.yaml +++ b/tests/config-default.yaml @@ -1,12 +1,10 @@ -executor: - backend: sequential data-access: mode: explicit-files files: - tests/data/nano_dimuon.root +executor: + backend: sequential processor: parallelize_over: files - columns: - - event - - Muon_pt + columns: 5 operation: sum diff --git a/tests/test-dask-local.yaml b/tests/test-dask-local.yaml deleted file mode 100644 index 2419858..0000000 --- a/tests/test-dask-local.yaml +++ /dev/null @@ -1,10 +0,0 @@ -executor: - backend: dask-local -data-access: - mode: explicit-files - files: - - tests/data/nano_dimuon.root -processor: - parallelize_over: files - columns: 10 - operation: sum diff --git a/tests/test-data-access.py b/tests/test-data-access.py new file mode 100644 index 0000000..b8d3c5b --- /dev/null +++ b/tests/test-data-access.py @@ -0,0 +1,25 @@ +from utils import run_tests + + +def test_data_access_explicit_files(b): + b.config["data-access"]["mode"] = "explicit-files" + b.config["data-access"]["files"] = ["tests/data/nano_dimuon.root"] + b.run() + print(f"Successfully tested accessing data via explicing list of files") + +def test_data_access_explicit_dirs(b): + b.config["data-access"]["mode"] = "explicit-dirs" + b.config["data-access"]["directories"] = ["tests/data/"] + b.run() + print(f"Successfully tested accessing data via explicing list of directories") + + +if __name__=='__main__': + run_tests( + config="tests/config-default.yaml", + functions=[ + test_data_access_explicit_files, + test_data_access_explicit_dirs, + ] + ) + diff --git a/tests/test-default.yaml b/tests/test-default.yaml deleted file mode 100644 index 6a6d14a..0000000 --- a/tests/test-default.yaml +++ /dev/null @@ -1,10 +0,0 @@ -executor: - backend: futures -data-access: - mode: explicit-files - files: - - tests/data/nano_dimuon.root -processor: - parallelize_over: files - columns: 10 - operation: sum diff --git a/tests/test-executors.py b/tests/test-executors.py new file mode 100644 index 0000000..7535ee3 --- /dev/null +++ b/tests/test-executors.py @@ -0,0 +1,31 @@ +from utils import run_tests + + +def test_executor_sequential(b): + b.config["executor"]["backend"] = "sequential" + b.run() + print(f"Successfully tested sequential executor") + +def test_executor_futures(b): + b.config["executor"]["backend"] = "futures" + b.run() + print(f"Successfully tested futures executor") + +def test_executor_dask_local(b): + b.config["executor"]["backend"] = "dask-local" + b.config["executor"]["workers"] = 1 + b.run() + print(f"Successfully tested dask-local executor") + + +if __name__=='__main__': + run_tests( + config="tests/config-default.yaml", + functions=[ + test_executor_sequential, + test_executor_futures, + test_executor_dask_local + ] + ) + + diff --git a/tests/test-futures.yaml b/tests/test-futures.yaml deleted file mode 100644 index 6a6d14a..0000000 --- a/tests/test-futures.yaml +++ /dev/null @@ -1,10 +0,0 @@ -executor: - backend: futures -data-access: - mode: explicit-files - files: - - tests/data/nano_dimuon.root -processor: - parallelize_over: files - columns: 10 - operation: sum diff --git a/tests/test-processing.py b/tests/test-processing.py new file mode 100644 index 0000000..8a5bd63 --- /dev/null +++ b/tests/test-processing.py @@ -0,0 +1,73 @@ +from utils import run_tests + + +def test_processor_columns_explicit(b): + b.config["processor"]["columns"] = ["Muon_pt", "Muon_eta"] + b.run() + print(f"Successfully tested processing explicit list of columns") + +def test_processor_columns_number(b): + b.config["processor"]["columns"] = 5 + b.run() + print(f"Successfully tested processing given number of columns") + +def test_processor_collections(b): + b.config["processor"]["columns"] = [] + b.config["processor"]["collections"] = ["Muon"] + b.run() + print(f"Successfully tested processing a collection of columns") + +def test_processor_operation_nothing(b): + b.config["processor"]["operation"] = "nothing" + b.run() + print(f"Successfully tested doing nothing to specified columns") + +def test_processor_operation_load(b): + b.config["processor"]["operation"] = "load_into_memory" + b.run() + print(f"Successfully tested loading specified columns into memory") + +def test_processor_parallelize_over_files(b): + b.config["processor"]["parallelize_over"] = "files" + b.config["executor"]["backend"] = "futures" + b.config["data-access"]["files"] = [ + "tests/data/nano_dimuon.root", + "tests/data/nano_dimuon.root" + ] + b.run() + print(f"Successfully tested parallelization over files") + +def test_processor_parallelize_over_columns(b): + b.config["processor"]["parallelize_over"] = "columns" + b.config["executor"]["backend"] = "futures" + b.config["processor"]["columns"] = 2 + b.run() + print(f"Successfully tested parallelization over files") + +def test_processor_parallelize_over_files_and_columns(b): + b.config["processor"]["parallelize_over"] = "files_and_columns" + b.config["executor"]["backend"] = "futures" + b.config["data-access"]["files"] = [ + "tests/data/nano_dimuon.root", + "tests/data/nano_dimuon.root" + ] + b.config["processor"]["columns"] = 2 + b.run() + print(f"Successfully tested parallelization over files and columns") + + +if __name__=='__main__': + run_tests( + config="tests/config-default.yaml", + functions=[ + test_processor_columns_explicit, + test_processor_columns_number, + test_processor_collections, + test_processor_operation_nothing, + test_processor_operation_load, + test_processor_parallelize_over_files, + test_processor_parallelize_over_columns, + test_processor_parallelize_over_files_and_columns, + ] + ) + diff --git a/tests/test-read-by-column.yaml b/tests/test-read-by-column.yaml deleted file mode 100644 index 6a6d14a..0000000 --- a/tests/test-read-by-column.yaml +++ /dev/null @@ -1,10 +0,0 @@ -executor: - backend: futures -data-access: - mode: explicit-files - files: - - tests/data/nano_dimuon.root -processor: - parallelize_over: files - columns: 10 - operation: sum diff --git a/tests/test-read-by-file.yaml b/tests/test-read-by-file.yaml deleted file mode 100644 index 6a6d14a..0000000 --- a/tests/test-read-by-file.yaml +++ /dev/null @@ -1,10 +0,0 @@ -executor: - backend: futures -data-access: - mode: explicit-files - files: - - tests/data/nano_dimuon.root -processor: - parallelize_over: files - columns: 10 - operation: sum diff --git a/tests/test-read-from-dir.yaml b/tests/test-read-from-dir.yaml deleted file mode 100644 index a2547c5..0000000 --- a/tests/test-read-from-dir.yaml +++ /dev/null @@ -1,10 +0,0 @@ -executor: - backend: futures -data-access: - mode: explicit-dirs - directories: - - tests/data/ -processor: - parallelize_over: files - columns: 10 - operation: sum diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 0000000..182e0ba --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,13 @@ +import os, sys +sys.path.append(os.getcwd()+"/af_benchmark") +import copy +from benchmark import Benchmark + +def run_tests(config, functions): + b = Benchmark(config) + for func in functions: + old_config = copy.deepcopy(b.config) + func(b) + b.reset() + b.config = old_config + \ No newline at end of file