Skip to content

Commit 0f974ce

Browse files
authored
chore: cleanup tests (#12)
* Cleaup tests * Rename dir: e2e_query -> e2e * Fix precommit * Unused imports * Update readme
1 parent 59945d6 commit 0f974ce

36 files changed

+99
-1140
lines changed

.github/actions/run-tests/action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,5 @@ runs:
3434
with:
3535
report_paths: "${{ inputs.working-directory }}/test-results/test-${{ inputs.report-suffix }}.xml"
3636
update_check: true
37-
include_passed: true
3837
annotate_notice: true
3938
job_name: ${{ inputs.report-job }}

.github/scripts/rest.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

.github/workflows/tests-e2e.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,20 @@ jobs:
4747
4848
- name: Run tests
4949
env:
50-
NEPTUNE_WORKSPACE: ${{ secrets.E2E_WORKSPACE }}
5150
NEPTUNE_E2E_WORKSPACE: ${{ secrets.E2E_WORKSPACE }}
5251
NEPTUNE_E2E_PROJECT: ${{ secrets[format('E2E_PROJECT{0}', matrix.env_suffix)] }}
53-
NEPTUNE_API_TOKEN: ${{ secrets[format('E2E_API_TOKEN{0}', matrix.env_suffix)] }}
54-
PROJECT_DIR: .
55-
TESTS_DIR: tests/e2e_query
52+
NEPTUNE_E2E_API_TOKEN: ${{ secrets[format('E2E_API_TOKEN{0}', matrix.env_suffix)] }}
5653
TEST_MARKERS: ${{ matrix.test_markers }}
5754
NEPTUNE_VERIFY_SSL: ${{ matrix.verify_ssl }}
5855
run: |
59-
pytest --junitxml="test-results/test-e2e.xml" ${TEST_MARKERS:+-m "$TEST_MARKERS"} "$TESTS_DIR"
56+
pytest --junitxml="test-results/test-e2e.xml" ${TEST_MARKERS:+-m "$TEST_MARKERS"} tests/e2e
6057
6158
- name: Report
6259
uses: mikepenz/action-junit-report@v5
6360
if: always()
6461
with:
6562
report_paths: "./test-results/test-e2e*.xml"
6663
update_check: true
67-
include_passed: true
6864
annotate_notice: true
6965
job_name: "e2e tests"
7066

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
poetry.lock
21
# Neptune data
32
.neptune/
43
**/.neptune/
@@ -128,3 +127,5 @@ stream.bin
128127

129128
# mocks
130129
MagicMock/
130+
131+
poetry.lock

poetry.lock

Lines changed: 0 additions & 843 deletions
This file was deleted.

src/neptune_query/internal/composition/type_inference.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Iterable,
2323
Optional,
2424
TypeVar,
25+
Union,
2526
)
2627

2728
from neptune_api.client import AuthenticatedClient
@@ -40,7 +41,7 @@
4041
)
4142
from .attributes import fetch_attribute_definitions
4243

43-
T = TypeVar("T", covariant=True)
44+
T = TypeVar("T", bound=Union[filters._Filter, filters._Attribute, None])
4445

4546

4647
@dataclass
@@ -84,10 +85,6 @@ class InferenceState(Generic[T]):
8485
attributes: list[AttributeInferenceState]
8586
result: T
8687

87-
@staticmethod
88-
def empty() -> "InferenceState[None]":
89-
return InferenceState(attributes=[], result=None)
90-
9188
@staticmethod
9289
def from_attribute(attribute: filters._Attribute) -> "InferenceState[filters._Attribute]":
9390
attribute_copy = copy.deepcopy(attribute)
@@ -103,7 +100,7 @@ def from_attribute(attribute: filters._Attribute) -> "InferenceState[filters._At
103100
return InferenceState(attributes=attribute_states, result=attribute_copy)
104101

105102
@staticmethod
106-
def from_filter(filter_: filters._Filter) -> "InferenceState[filters._Filter]":
103+
def from_filter(filter_: filters._Filter) -> "InferenceState[Optional[filters._Filter]]":
107104
def _walk_attributes(experiment_filter: filters._Filter) -> Iterable[filters._Attribute]:
108105
if isinstance(experiment_filter, filters._AttributeValuePredicate):
109106
yield experiment_filter.attribute
@@ -169,7 +166,7 @@ def infer_attribute_types_in_filter(
169166
fetch_attribute_definitions_executor: Executor,
170167
) -> InferenceState[Optional[filters._Filter]]:
171168
if filter_ is None:
172-
return InferenceState.empty()
169+
return InferenceState(attributes=[], result=None)
173170

174171
state = InferenceState.from_filter(filter_)
175172
if state.is_complete():

tests/README.md

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
1-
# Important notes
1+
# Environment variables
22

3-
## Prepopulated test data
3+
* `NEPTUNE_E2E_API_TOKEN` - an API TOKEN to use in the e2e tests
4+
* `NEPTUNE_E2E_WORKSPACE` - a workspace that e2e tests can create projects in
5+
* `NEPTUNE_E2E_PROJECT` - a project to use for (some of) the e2e tests
6+
* `NEPTUNE_E2E_REUSE_PROJECT` - see below
7+
* `NEPTUNE_E2E_VERIFY_SSL` - whether to verify SSL certificates when running the e2e tests;
8+
only required if the instance you're running the e2e tests against has an invalid cert
49

5-
A subset of the tests in the `e2e` directory are end-to-end tests that assume a
6-
specific data layout in a project.
10+
## Projects used and created in end-to-end tests
11+
Each e2e run uses 2 projects. You can control them with environment variables.
712

8-
This data is populated using the `populate_projects.py` script, which
9-
has comments explaining the layout.
13+
- The first project is specified explicitly.\
14+
If the data required by a test doesn't exist in this project, it's populated during the test run.\
15+
Example: `NEPTUNE_E2E_PROJECT="neptune/e2e-tests"`
1016

11-
The script *must* be run only **once** on a fresh project to set up the
12-
necessary data for the tests to run successfully.
1317

14-
The tests that rely on this data are:
18+
- The second project's name is generated depending on the `NEPTUNE_E2E_REUSE_PROJECT` env.\
19+
The project is created / expected in the workspace under the `NEPTUNE_E2E_WORKSPACE` env.
1520

16-
* `test_dataframe_values.py`
17-
* `test_run_filtering.py`
18-
* `test_run_list.py`
21+
- If `NEPTUNE_E2E_REUSE_PROJECT=false` (the default), the project name is .e.g. `pye2e-runs-<datetime>-v1`.\
22+
The project is always created and populated with data.
1923

20-
## Environment variables
21-
22-
* `NEPTUNE_API_TOKEN` - API token to use
23-
* `NEPTUNE_E2E_PROJECT_PREPOPULATED` - project name to use for tests that require a project
24-
with fixed data populated by `populate_projects.py` and **do not** populate the
25-
project during execution. The test runner script creates a temporary project for
26-
that purpose. If not set, `NEPTUNE_PROJECT` is used.
27-
* `NEPTUNE_E2E_PROJECT` - project name to use for tests that create Runs during
28-
execution. This can be an existing project in which it's fine to create multiple
29-
Runs with different data. If not set, `NEPTUNE_PROJECT` is used.
30-
* `NEPTUNE_E2E_CUSTOM_RUN_ID` (optional) - if set, it should be `sys/custom_run_id`
31-
of an existing Run. This avoids creating a new Run for tests that log data,
32-
if this is for some reason required.
24+
- If `NEPTUNE_E2E_REUSE_PROJECT=true`, the project name is `pye2e-runs-<hash>-v1`.\
25+
The name contains a hash of the data the tests need in this project.\
26+
If the project doesn't exist, it's created and populated.
Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,42 @@
1818
get_config_and_token_urls,
1919
)
2020
from neptune_query.internal.composition import concurrency
21-
from neptune_query.internal.context import set_project
21+
from neptune_query.internal.context import (
22+
set_api_token,
23+
set_project,
24+
)
2225
from neptune_query.internal.filters import _Filter
2326
from neptune_query.internal.identifiers import RunIdentifier
2427
from neptune_query.internal.retrieval.search import fetch_experiment_sys_attrs
25-
from tests.e2e_query.data import (
28+
from tests.e2e.data import (
2629
FILE_SERIES_STEPS,
2730
NOW,
2831
PATH,
2932
TEST_DATA,
3033
)
3134

32-
API_TOKEN_ENV_NAME: str = "NEPTUNE_API_TOKEN"
33-
3435

3536
@dataclass
3637
class Project:
3738
project_identifier: str
3839

3940

4041
@pytest.fixture(scope="session")
41-
def client() -> AuthenticatedClient:
42-
api_token = os.getenv(API_TOKEN_ENV_NAME)
42+
def api_token() -> str:
43+
api_token = os.getenv("NEPTUNE_E2E_API_TOKEN")
44+
if api_token is None:
45+
raise RuntimeError("NEPTUNE_E2E_API_TOKEN environment variable is not set")
46+
return api_token
47+
48+
49+
@pytest.fixture(autouse=True)
50+
def set_api_token_auto(api_token) -> None:
51+
"""Set the API token for the session."""
52+
set_api_token(api_token)
53+
54+
55+
@pytest.fixture(scope="session")
56+
def client(api_token) -> AuthenticatedClient:
4357
credentials = Credentials.from_api_key(api_key=api_token)
4458
config, token_urls = get_config_and_token_urls(credentials=credentials, proxies=None)
4559
client = create_auth_api_client(
@@ -60,25 +74,15 @@ def executor() -> Executor:
6074

6175

6276
@pytest.fixture(scope="module")
63-
def project(request):
64-
# Assume the project name and API token are set in the environment using the standard
65-
# NEPTUNE_PROJECT and NEPTUNE_API_TOKEN variables.
66-
#
67-
# We also allow overriding the project name per module by setting the
68-
# module-level `NEPTUNE_PROJECT` variable.
69-
project_identifier = getattr(request.module, "NEPTUNE_PROJECT", None)
77+
def project():
78+
project_identifier = os.getenv("NEPTUNE_E2E_PROJECT")
7079
if project_identifier is None:
71-
project_identifier = os.getenv("NEPTUNE_PROJECT")
72-
if project_identifier is None:
73-
raise ValueError(
74-
"Project identifier not provided. Set NEPTUNE_PROJECT environment variable or "
75-
"define it in the module using `NEPTUNE_PROJECT = 'your_project_name'`."
76-
)
80+
raise RuntimeError("NEPTUNE_E2E_PROJECT environment variable is not set")
7781
return Project(project_identifier=project_identifier)
7882

7983

8084
@pytest.fixture(scope="module")
81-
def run_with_attributes(project, client):
85+
def run_with_attributes(project, api_token, client):
8286
runs = {}
8387
for experiment in TEST_DATA.experiments:
8488
project_id = project.project_identifier
@@ -94,6 +98,7 @@ def run_with_attributes(project, client):
9498
continue
9599

96100
run = Run(
101+
api_token=api_token,
97102
project=project_id,
98103
run_id=experiment.run_id,
99104
experiment_name=experiment.name,

0 commit comments

Comments
 (0)