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