Skip to content

Commit

Permalink
Merge pull request #46 from MagnivOrg/test-restructuring
Browse files Browse the repository at this point in the history
Test restructuring
  • Loading branch information
gusrasch authored Nov 4, 2022
2 parents 6799509 + 1b839a8 commit 363112c
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 83 deletions.
58 changes: 7 additions & 51 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,9 @@
### Magniv tests

Goal: Create robust comprehensive unit and integration tests to empower fast development.

Structure: all tests stored in top level folder called “tests” inner folders structured by test type eg

-Tests

```
- unit_tests
- integration_tests
- standalone_tests
Test structure corresponds to directory structure within `magniv-core\magniv`:
- build
- core
- export
- run
- scripts
- utils
```

Stack:

```
pytest
https://github.com/pytest-dev/pytest
coverage
https://github.com/nedbat/coveragepy
```

Schematics:

```
build.py:
integration_tests:
todo:
- test where there are nested folders with tasks in them, make sure that all those tasks show in the `dump.json` and that the `dump.json` is accurate
- test when there are multiple task files in the same folder and make sure all of them show up
- test when there is a nested folder that has its own `requirements.txt` -- verify that the `dump.json` reflects that the correct `requirements.txt` is being used
- test when there is a nested folder w/o a `requirements.txt`, make sure it uses the next parents `requirements.txt`
- test_name
unit_tests:
todo:
test_build.py:
- requirements in nested dir
- requirements top level dir
- gets list of decorated nodes from ast
- gets all decorated tasks from file as list
- finds all files in dir that have magniv task decorators
- saves dump.json to expected path
- throws oserror if no file with decorated task is found
- throws oserror if dir specified dir not found
- multiple tasks within one file
test_build_imports.py
- import magniv
- from magniv.core import task
- from magniv import core as ___

```
A unit test for a given method should be created under the directory that corresponds to where the original method lives in the codebase. Integration tests can be added separately if they are implemented.
1 change: 1 addition & 0 deletions tests/build_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TESTS IN THIS DIRECTORY SHOULD TEST CODE UNDER magniv\build
File renamed without changes.
File renamed without changes.
30 changes: 2 additions & 28 deletions tests/unit_tests/test_build.py → tests/build_tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
get_task_list,
save_tasks,
)
from tests.unit_tests.fixtures.test_build import TestBuild
from tests.unit_tests.fixtures.test_files import VALID_TEST_FILE

# FIXME: make this use base class from fixtures dir
from tests.build_tests.fixtures.test_build import TestBuild
from tests.build_tests.fixtures.test_files import VALID_TEST_FILE


class TestValidBuild(TestBuild):
Expand Down Expand Up @@ -88,30 +86,6 @@ def test_reqs_dependency(self):
with pytest.raises(OSError):
save_tasks(task_folder="")

@pytest.fixture
def subdir_reqs_file(self, tmpdir):
"""
It creates a directory structure with a requirements.txt file in it
:param tmpdir: This is a pytest fixture that creates a temporary directory for us to use
:return: The path to the requirements.txt file.
"""
tmpdir.mkdir("tasks").mkdir("subdir").mkdir("subsubdir").join("requirements.txt").write(
"magniv"
)
return str(tmpdir.join("tasks/subdir/subsubdir"))

def test_subdirreqs_filepath(self, subdir_reqs_file):
"""
`save_tasks` is a function that takes a folder path as an argument and saves all the tasks in
that folder to a file
:param subdir_reqs_file: a filepath to a requirements.txt file in a subdirectory
"""
json_pth = f"{subdir_reqs_file}/dump.json"
save_tasks(task_folder=subdir_reqs_file, dump_save_pth=json_pth)
assert os.path.exists(json_pth) == True

def test_task_builds_with_valid_custom_resources(self, folder):
task_list = get_task_list([{"filepath": f"{folder}/main.py", "req": None}])
for task in task_list:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

from magniv.build.build import get_decorated_nodes
from tests.unit_tests.fixtures.test_build import TestBuild
from tests.unit_tests.fixtures.test_files import GET_DECORATED_NODES_FILE
from tests.build_tests.fixtures.test_build import TestBuild
from tests.build_tests.fixtures.test_files import GET_DECORATED_NODES_FILE


class TestGetDecoratedNodes(TestBuild):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

from magniv.build.build import build
from tests.unit_tests.fixtures.test_build import TestBuild
from tests.unit_tests.fixtures.test_files import (
from tests.build_tests.fixtures.test_build import TestBuild
from tests.build_tests.fixtures.test_files import (
INVALID_KWARG_FILE,
INVALID_TASK_KEY_FILE,
INVALID_TRIGGER_FILE,
Expand Down
1 change: 1 addition & 0 deletions tests/core_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TESTS IN THIS DIRECTORY SHOULD TEST CODE UNDER magniv\core
6 changes: 6 additions & 0 deletions tests/core_tests/test_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from magniv.core.task import task


class TestTask:
def test_task_does_not_fail(self):
assert task()
1 change: 1 addition & 0 deletions tests/export_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TESTS IN THIS DIRECTORY SHOULD TEST CODE UNDER magniv\export
1 change: 1 addition & 0 deletions tests/export_tests/test_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO: implement export testing
Empty file removed tests/unit_tests/__init__.py
Empty file.

0 comments on commit 363112c

Please sign in to comment.