From b93ca8d543c344fdb461909392fd74979fa76315 Mon Sep 17 00:00:00 2001 From: Stefan Krawczyk Date: Sun, 3 Dec 2023 17:01:42 -0800 Subject: [PATCH] test --- .pre-commit-config.yaml | 2 +- contrib/setup.cfg | 1 + setup.cfg | 1 + tests/execution/test_executors.py | 17 +++++++++-------- tests/execution/test_node_grouping.py | 4 ++-- tests/function_modifiers/test_macros.py | 3 ++- tests/function_modifiers/test_recursive.py | 3 ++- tests/function_modifiers/test_validation.py | 11 ++++++----- tests/io/test_materialization.py | 5 +++-- tests/test_caching.py | 3 ++- tests/test_common.py | 5 +++-- tests/test_default_data_quality.py | 13 +++++++------ tests/test_end_to_end.py | 7 ++++--- tests/test_graph.py | 15 +++++++++------ tests/test_hamilton_driver.py | 13 +++++++------ 15 files changed, 59 insertions(+), 44 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b8abef426..5415f2460 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: rev: '5.12.0' hooks: - id: isort - args: ["--profile", "black", --line-length=100] + args: ["--profile", "black", "--line-length=100", "--known-local-folder", "tests", "-p", "hamilton"] - repo: https://github.com/pycqa/flake8 rev: 6.1.0 hooks: diff --git a/contrib/setup.cfg b/contrib/setup.cfg index 6b1dae301..bc5f20b65 100644 --- a/contrib/setup.cfg +++ b/contrib/setup.cfg @@ -15,3 +15,4 @@ ignore = [isort] known_first_party=hamilton +known_local_folder=tests diff --git a/setup.cfg b/setup.cfg index 6b1dae301..bc5f20b65 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,3 +15,4 @@ ignore = [isort] known_first_party=hamilton +known_local_folder=tests diff --git a/tests/execution/test_executors.py b/tests/execution/test_executors.py index d16b8a9bf..6630d1698 100644 --- a/tests/execution/test_executors.py +++ b/tests/execution/test_executors.py @@ -3,14 +3,6 @@ import numpy as np import pytest -from tests.resources.dynamic_parallelism import ( - inputs_in_collect, - no_parallel, - parallel_collect_multiple_arguments, - parallel_complex, - parallel_delayed, - parallel_linear_basic, -) import hamilton.ad_hoc_utils from hamilton import base, driver @@ -30,6 +22,15 @@ ) from hamilton.htypes import Collect, Parallelizable +from tests.resources.dynamic_parallelism import ( + inputs_in_collect, + no_parallel, + parallel_collect_multiple_arguments, + parallel_complex, + parallel_delayed, + parallel_linear_basic, +) + ADAPTER = base.DefaultAdapter() diff --git a/tests/execution/test_node_grouping.py b/tests/execution/test_node_grouping.py index 0bf675082..f3d4cc431 100644 --- a/tests/execution/test_node_grouping.py +++ b/tests/execution/test_node_grouping.py @@ -1,5 +1,3 @@ -from tests.resources.dynamic_parallelism import no_parallel, parallel_complex, parallel_linear_basic - from hamilton import ad_hoc_utils, base, graph, node from hamilton.execution import grouping from hamilton.execution.grouping import ( @@ -12,6 +10,8 @@ from hamilton.graph import FunctionGraph from hamilton.node import NodeType +from tests.resources.dynamic_parallelism import no_parallel, parallel_complex, parallel_linear_basic + def test_group_individually(): fn_graph = FunctionGraph.from_modules(no_parallel, config={}) diff --git a/tests/function_modifiers/test_macros.py b/tests/function_modifiers/test_macros.py index 7fc03bb80..5f941cb31 100644 --- a/tests/function_modifiers/test_macros.py +++ b/tests/function_modifiers/test_macros.py @@ -3,7 +3,6 @@ import pandas as pd import pytest -import tests.resources.pipe import hamilton.function_modifiers from hamilton import base, driver, function_modifiers, models, node @@ -12,6 +11,8 @@ from hamilton.function_modifiers.macros import Applicable, ensure_function_empty, pipe, step from hamilton.node import DependencyType +import tests.resources.pipe + def test_no_code_validator(): def no_code(): diff --git a/tests/function_modifiers/test_recursive.py b/tests/function_modifiers/test_recursive.py index 198a3212f..84d3674f3 100644 --- a/tests/function_modifiers/test_recursive.py +++ b/tests/function_modifiers/test_recursive.py @@ -3,7 +3,6 @@ from typing import Tuple import pytest -import tests.resources.reuse_subdag from hamilton import ad_hoc_utils, graph from hamilton.function_modifiers import ( @@ -18,6 +17,8 @@ from hamilton.function_modifiers.dependencies import source from hamilton.function_modifiers.recursive import _validate_config_inputs +import tests.resources.reuse_subdag + def test_collect_function_fns(): val = random.randint(0, 100000) diff --git a/tests/function_modifiers/test_validation.py b/tests/function_modifiers/test_validation.py index af06e8dfc..f22df6e36 100644 --- a/tests/function_modifiers/test_validation.py +++ b/tests/function_modifiers/test_validation.py @@ -1,11 +1,6 @@ import numpy as np import pandas as pd import pytest -from tests.resources.dq_dummy_examples import ( - DUMMY_VALIDATORS_FOR_TESTING, - SampleDataValidator2, - SampleDataValidator3, -) from hamilton import node from hamilton.data_quality.base import DataValidationError, ValidationResult @@ -17,6 +12,12 @@ ) from hamilton.node import DependencyType +from tests.resources.dq_dummy_examples import ( + DUMMY_VALIDATORS_FOR_TESTING, + SampleDataValidator2, + SampleDataValidator3, +) + def test_check_output_node_transform(): decorator = check_output( diff --git a/tests/io/test_materialization.py b/tests/io/test_materialization.py index e009fc461..036e5c1d1 100644 --- a/tests/io/test_materialization.py +++ b/tests/io/test_materialization.py @@ -2,8 +2,6 @@ from typing import Any, Collection, Dict, List, Optional, Tuple, Type import pytest -import tests.resources.cyclic_functions -import tests.resources.test_default_args from hamilton import base, graph, node, registry from hamilton.function_modifiers import load_from, save_to, value @@ -20,6 +18,9 @@ to, ) +import tests.resources.cyclic_functions +import tests.resources.test_default_args + global_mock_data_saver_cache = {} diff --git a/tests/test_caching.py b/tests/test_caching.py index 64ca85124..7f5527f0e 100644 --- a/tests/test_caching.py +++ b/tests/test_caching.py @@ -3,12 +3,13 @@ import pandas as pd import pytest -from tests import nodes from hamilton import base from hamilton.driver import Driver from hamilton.experimental import h_cache +from tests import nodes + @pytest.fixture def df(): diff --git a/tests/test_common.py b/tests/test_common.py index c904b4786..1638ae208 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -1,9 +1,10 @@ import pytest -import tests.resources.cyclic_functions -import tests.resources.test_default_args from hamilton import common, driver +import tests.resources.cyclic_functions +import tests.resources.test_default_args + class Object: """Dummy class to test with.""" diff --git a/tests/test_default_data_quality.py b/tests/test_default_data_quality.py index 86225ed17..28173477d 100644 --- a/tests/test_default_data_quality.py +++ b/tests/test_default_data_quality.py @@ -6,12 +6,6 @@ import numpy as np import pandas as pd import pytest -from tests.resources.dq_dummy_examples import ( - DUMMY_VALIDATORS_FOR_TESTING, - SampleDataValidator1, - SampleDataValidator2, - SampleDataValidator3, -) import hamilton.data_quality.base from hamilton.data_quality import default_validators @@ -21,6 +15,13 @@ resolve_default_validators, ) +from tests.resources.dq_dummy_examples import ( + DUMMY_VALIDATORS_FOR_TESTING, + SampleDataValidator1, + SampleDataValidator2, + SampleDataValidator3, +) + @pytest.mark.parametrize( "output_type, kwargs, importance, expected", diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py index 5ba389fa8..9c7cddc70 100644 --- a/tests/test_end_to_end.py +++ b/tests/test_end_to_end.py @@ -4,9 +4,6 @@ from typing import Any, Callable, Dict, List, Type import pytest -import tests.resources.data_quality -import tests.resources.dynamic_config -import tests.resources.overrides from hamilton import ad_hoc_utils, base, driver, settings from hamilton.base import DefaultAdapter @@ -15,6 +12,10 @@ from hamilton.function_modifiers import source, value from hamilton.io.materialization import from_, to +import tests.resources.data_quality +import tests.resources.dynamic_config +import tests.resources.overrides + @pytest.mark.parametrize( "driver_factory", diff --git a/tests/test_graph.py b/tests/test_graph.py index f107b3016..f99fe36e9 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -5,6 +5,13 @@ import pandas as pd import pytest + +import hamilton.graph_utils +import hamilton.htypes +from hamilton import ad_hoc_utils, base, graph, node +from hamilton.execution import graph_functions +from hamilton.node import NodeType + import tests.resources.bad_functions import tests.resources.compatible_input_types import tests.resources.config_modifier @@ -22,12 +29,6 @@ import tests.resources.test_default_args import tests.resources.typing_vs_not_typing -import hamilton.graph_utils -import hamilton.htypes -from hamilton import ad_hoc_utils, base, graph, node -from hamilton.execution import graph_functions -from hamilton.node import NodeType - def test_find_functions(): """Tests that we filter out _ functions when passed a module and don't pull in anything from the imports.""" @@ -240,6 +241,8 @@ def test_add_dependency_input_nodes_compatible_types_order_check(): """Tests that if functions request an input that we correctly accept compatible types independent of order. This just reorders test_add_dependency_input_nodes_compatible_types to ensure the outcome does not change. + + 123 """ b_sig = inspect.signature(tests.resources.compatible_input_types.b) c_sig = inspect.signature(tests.resources.compatible_input_types.c) diff --git a/tests/test_hamilton_driver.py b/tests/test_hamilton_driver.py index 2856520af..1a4260be4 100644 --- a/tests/test_hamilton_driver.py +++ b/tests/test_hamilton_driver.py @@ -2,12 +2,6 @@ import pandas as pd import pytest -import tests.resources.cyclic_functions -import tests.resources.dummy_functions -import tests.resources.dynamic_parallelism.parallel_linear_basic -import tests.resources.tagging -import tests.resources.test_default_args -import tests.resources.very_simple_dag from hamilton import base, node from hamilton.driver import ( @@ -20,6 +14,13 @@ from hamilton.execution import executors from hamilton.io.materialization import to +import tests.resources.cyclic_functions +import tests.resources.dummy_functions +import tests.resources.dynamic_parallelism.parallel_linear_basic +import tests.resources.tagging +import tests.resources.test_default_args +import tests.resources.very_simple_dag + """This file tests driver capabilities. Anything involving execution is tested for multiple executors/driver configuration. Anything not involving execution is tested for just the single driver configuration.