From d3b21a7c2bc60adb2714d12d4e24891adff98d3b Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Thu, 17 Jun 2021 20:50:17 +0000 Subject: [PATCH] Add unit tests --- .flake8 | 2 +- .github/workflows/pytest.yaml | 35 +++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ setup.cfg | 3 +++ spack.yaml | 2 ++ tests/__init__.py | 0 tests/datasets/__init__.py | 0 tests/datasets/test_utils.py | 22 ++++++++++++++++++++++ tests/transforms/__init__.py | 0 9 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pytest.yaml create mode 100644 tests/__init__.py create mode 100644 tests/datasets/__init__.py create mode 100644 tests/datasets/test_utils.py create mode 100644 tests/transforms/__init__.py diff --git a/.flake8 b/.flake8 index 7319e5296..80c117452 100644 --- a/.flake8 +++ b/.flake8 @@ -17,5 +17,5 @@ exclude = # Git .git/, -application-import-names = torchgeo +application-import-names = docs,tests,torchgeo import-order-style = google diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml new file mode 100644 index 000000000..ab1e2f274 --- /dev/null +++ b/.github/workflows/pytest.yaml @@ -0,0 +1,35 @@ +name: pytest +on: + push: + branches: + - main + paths: + - '**.py' + - 'requirements.txt' + - '.github/workflows/pytest.yaml' + pull_request: + branches: + - main + paths: + - '**.py' + - 'requirements.txt' + - '.github/workflows/pytest.yaml' +jobs: + pytest: + name: pytest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + python-version: [3.5, 3.6, 3.7, 3.8, 3.9] + steps: + - name: Clone repo + uses: actions/checkout@v2 + - name: Set up python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: pip3 install -r requirements.txt + - name: Run pytest checks + run: pytest diff --git a/requirements.txt b/requirements.txt index 2690115d3..0e2c86325 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,8 @@ mypy opencv-python pillow pycocotools +pytest +pytest-cov pytorch-sphinx-theme radiant-mlhub>=0.2.1 rarfile diff --git a/setup.cfg b/setup.cfg index 83f72cb7e..df3949fd2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,6 +30,9 @@ install_requires = python_requires = >= 3.5 packages = find: +[options.packages.find] +include = torchgeo + [options.extras_require] cv4akenyacroptype = radiant-mlhub>=0.2.1 diff --git a/spack.yaml b/spack.yaml index ceffa5f75..2d2b7c554 100644 --- a/spack.yaml +++ b/spack.yaml @@ -8,6 +8,8 @@ spack: - py-mypy - py-pillow-simd - py-pycocotools + - py-pytest + - py-pytest-cov - py-pytorch-sphinx-theme - "py-radiant-mlhub@0.2.1:" - py-rarfile diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/datasets/__init__.py b/tests/datasets/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/datasets/test_utils.py b/tests/datasets/test_utils.py new file mode 100644 index 000000000..c8a950db9 --- /dev/null +++ b/tests/datasets/test_utils.py @@ -0,0 +1,22 @@ +import pathlib + +from torchgeo.datasets.utils import working_dir + + +def test_existing_directory(tmp_path: pathlib.Path) -> None: + subdir = tmp_path / "foo" / "bar" + subdir.mkdir(parents=True) + + assert subdir.exists() + + with working_dir(str(subdir)): + assert subdir.cwd() == subdir + + +def test_nonexisting_directory(tmp_path: pathlib.Path) -> None: + subdir = tmp_path / "foo" / "bar" + + assert not subdir.exists() + + with working_dir(str(subdir), create=True): + assert subdir.cwd() == subdir diff --git a/tests/transforms/__init__.py b/tests/transforms/__init__.py new file mode 100644 index 000000000..e69de29bb