diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 384cf20..1c18594 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -116,6 +116,7 @@ jobs: with: repository: MODFLOW-USGS/modflow6-largetestmodels path: modflow6-largetestmodels + token: ${{ github.token }} - name: Install executables uses: modflowpy/install-modflow-action@v1 @@ -160,10 +161,22 @@ jobs: working-directory: modflow6-examples/etc run: python ci_build_files.py - - name: Run tests + - name: Run local tests working-directory: modflow-devtools env: BIN_PATH: ~/.local/bin/modflow REPOS_PATH: ${{ github.workspace }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: pytest -v -n auto --durations 0 \ No newline at end of file + GITHUB_TOKEN: ${{ github.token }} + run: pytest -v -n auto --durations 0 --ignore modflow_devtools/test/test_download.py + + - name: Run network-dependent tests + # only invoke the GH API on one OS and Python version + # to avoid rate limits (1000 rqs / hour / repository) + # https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration#usage-limits + if: runner.os == 'Linux' && matrix.python == '3.8' + working-directory: modflow-devtools + env: + BIN_PATH: ~/.local/bin/modflow + REPOS_PATH: ${{ github.workspace }} + GITHUB_TOKEN: ${{ github.token }} + run: pytest -v -n auto --durations 0 modflow_devtools/test/test_download.py \ No newline at end of file diff --git a/HISTORY.md b/HISTORY.md index a97d63f..51bb447 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,13 @@ +### Version 0.1.8 + +#### New features + +* [feat(fixtures)](https://github.com/MODFLOW-USGS/modflow-devtools/commit/3bf76d587a04954cc68a07d38e48876d42f06b58): Discover external model repo dirs with .git suffix (#80). Committed by w-bonelli on 2023-04-21. + +#### Bug fixes + +* [fix(multiple)](https://github.com/MODFLOW-USGS/modflow-devtools/commit/2307add30eb3134a786f7c722656b4d99a0fe91a): Fix some CI and fixture issues (#81). Committed by w-bonelli on 2023-04-21. + ### Version 0.1.7 #### Refactoring diff --git a/docs/conf.py b/docs/conf.py index 661a7d0..eb7b8a5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -8,7 +8,7 @@ project = "modflow-devtools" author = "MODFLOW Team" -release = "0.1.7" +release = "0.1.8" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/docs/md/fixtures.md b/docs/md/fixtures.md index 78f178d..ff1b2f5 100644 --- a/docs/md/fixtures.md +++ b/docs/md/fixtures.md @@ -55,7 +55,7 @@ See the [installation docs](install.md) for more information on installing test ### Configuration -It is recommended to set the environment variable `REPOS_PATH` to the location of the model repositories on the filesystem. Model repositories must live side-by-side in this location, and repository directories are expected to be named identically to GitHub repositories. If `REPOS_PATH` is not configured, `modflow-devtools` assumes tests are being run from an `autotest` subdirectory of the consuming project's root, and model repos live side-by-side with the consuming project. If this guess is incorrect and repositories cannot be found, tests requesting these fixtures will be skipped. +It is recommended to set the environment variable `REPOS_PATH` to the location of the model repositories on the filesystem. Model repositories must live side-by-side in this location, and repository directories are expected to be named identically to GitHub repositories (the directory may have a `.git` suffix). If `REPOS_PATH` is not configured, `modflow-devtools` assumes tests are being run from an `autotest` subdirectory of the consuming project's root, and model repos live side-by-side with the consuming project. If this guess is incorrect and repositories cannot be found, tests requesting these fixtures will be skipped. **Note:** by default, all models found in the respective external repository will be returned by these fixtures. It is up to the consuming project to exclude models if needed. This can be accomplished by: diff --git a/modflow_devtools/__init__.py b/modflow_devtools/__init__.py index 3f3bd85..bce77e5 100644 --- a/modflow_devtools/__init__.py +++ b/modflow_devtools/__init__.py @@ -1,6 +1,6 @@ __author__ = "Joseph D. Hughes" -__date__ = "Apr 18, 2023" -__version__ = "0.1.7" +__date__ = "Apr 21, 2023" +__version__ = "0.1.8" __maintainer__ = "Joseph D. Hughes" __email__ = "jdhughes@usgs.gov" __status__ = "Production" diff --git a/modflow_devtools/fixtures.py b/modflow_devtools/fixtures.py index cc59a72..83cba6a 100644 --- a/modflow_devtools/fixtures.py +++ b/modflow_devtools/fixtures.py @@ -190,15 +190,33 @@ def pytest_generate_tests(metafunc): repos_path = Path(repos_path) else: # by default, assume external repositories are - # in the same directory as the current project - # and tests are run from /autotest. - # if no models are found, tests requesting the - # fixtures will be skipped. + # level (side-by-side) on the filesystem with + # the consuming project. also assume tests are + # run from /autotest. + # + # external model repo directories are expected + # to be named identically to the GitHub repos, + # e.g. "modflow6-testmodels", with an optional + # ".git" suffix appended to the directory name. + # + # if model repositories are not found in either + # the default location or in REPOS_PATH, tests + # requesting these fixtures will be skipped. repos_path = Path.cwd().parent.parent + def get_repo_path(repo_name: str) -> Optional[Path]: + """Get the path for the repository with the given name + (optionally with .git suffix), or None if not found""" + repo_path = repos_path / repo_name + if not repo_path.is_dir(): + repo_path = repos_path / (repo_name + ".git") + if not repo_path.is_dir(): + repo_path = None + return repo_path + key = "test_model_mf6" if key in metafunc.fixturenames: - repo_path = repos_path / "modflow6-testmodels" + repo_path = get_repo_path("modflow6-testmodels") namefile_paths = ( get_namefile_paths( repo_path / "mf6", @@ -207,7 +225,7 @@ def pytest_generate_tests(metafunc): selected=models_selected, packages=packages_selected, ) - if repo_path.is_dir() + if repo_path else [] ) metafunc.parametrize( @@ -216,7 +234,7 @@ def pytest_generate_tests(metafunc): key = "test_model_mf5to6" if key in metafunc.fixturenames: - repo_path = repos_path / "modflow6-testmodels" + repo_path = get_repo_path("modflow6-testmodels") namefile_paths = ( get_namefile_paths( repo_path / "mf5to6", @@ -226,7 +244,7 @@ def pytest_generate_tests(metafunc): selected=models_selected, packages=packages_selected, ) - if repo_path.is_dir() + if repo_path else [] ) metafunc.parametrize( @@ -235,7 +253,7 @@ def pytest_generate_tests(metafunc): key = "large_test_model" if key in metafunc.fixturenames: - repo_path = repos_path / "modflow6-largetestmodels" + repo_path = get_repo_path("modflow6-largetestmodels") namefile_paths = ( get_namefile_paths( repo_path, @@ -245,7 +263,7 @@ def pytest_generate_tests(metafunc): selected=models_selected, packages=packages_selected, ) - if repo_path.is_dir() + if repo_path else [] ) metafunc.parametrize( @@ -254,7 +272,7 @@ def pytest_generate_tests(metafunc): key = "example_scenario" if key in metafunc.fixturenames: - repo_path = repos_path / "modflow6-examples" + repo_path = get_repo_path("modflow6-examples") def is_nested(namfile_path: PathLike) -> bool: p = Path(namfile_path) @@ -291,7 +309,12 @@ def group_examples(namefile_paths) -> Dict[str, List[Path]]: def get_examples(): # find MODFLOW 6 namfiles - namfiles = [p for p in (repo_path / "examples").rglob("mfsim.nam")] + examples_path = repo_path / "examples" + namfiles = ( + [p for p in examples_path.rglob("mfsim.nam")] + if examples_path.is_dir() + else [] + ) # group by scenario examples = group_examples(namfiles) @@ -334,7 +357,7 @@ def get_examples(): return examples - example_scenarios = get_examples() if repo_path.is_dir() else dict() + example_scenarios = get_examples() if repo_path else dict() metafunc.parametrize( key, [(name, nfps) for name, nfps in example_scenarios.items()], diff --git a/modflow_devtools/test/test_download.py b/modflow_devtools/test/test_download.py index 467ebd1..9fbfff7 100644 --- a/modflow_devtools/test/test_download.py +++ b/modflow_devtools/test/test_download.py @@ -69,7 +69,7 @@ def test_list_artifacts(tmp_path, name, per_page): "MODFLOW-USGS/modflow6", name=name, per_page=per_page, - max_pages=3, + max_pages=2, verbose=True, ) diff --git a/modflow_devtools/test/test_misc.py b/modflow_devtools/test/test_misc.py index 70b2ac5..9ff517e 100644 --- a/modflow_devtools/test/test_misc.py +++ b/modflow_devtools/test/test_misc.py @@ -162,7 +162,7 @@ def test_get_model_paths_largetestmodels(): reason="repos not found", ) @pytest.mark.parametrize( - "models", [(_examples_path, 63), (_largetestmodels_repo_path, 15)] + "models", [(_examples_path, 63), (_largetestmodels_repo_path, 16)] ) def test_get_model_paths_exclude_patterns(models): path, expected_count = models @@ -205,7 +205,7 @@ def test_get_namefile_paths_largetestmodels(): reason="repos not found", ) @pytest.mark.parametrize( - "models", [(_examples_path, 43), (_largetestmodels_repo_path, 18)] + "models", [(_examples_path, 43), (_largetestmodels_repo_path, 19)] ) def test_get_namefile_paths_exclude_patterns(models): path, expected_count = models diff --git a/version.txt b/version.txt index a1e1395..84aa3a7 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.1.7 \ No newline at end of file +0.1.8 \ No newline at end of file