From 29179fa26603a42220843d9758555c85fa4b7a63 Mon Sep 17 00:00:00 2001 From: agisga <11449372+agisga@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:22:37 -0500 Subject: [PATCH 1/4] cli to replace python main_out.py --- domainlab/cli.py | 22 ++++++++++++++++++++++ pyproject.toml | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 domainlab/cli.py diff --git a/domainlab/cli.py b/domainlab/cli.py new file mode 100644 index 000000000..e2e09282b --- /dev/null +++ b/domainlab/cli.py @@ -0,0 +1,22 @@ +from domainlab.arg_parser import parse_cmd_args +from domainlab.exp.exp_cuda_seed import set_seed # reproducibility +from domainlab.exp.exp_main import Exp +from domainlab.exp_protocol import aggregate_results +from domainlab.utils.generate_benchmark_plots import gen_benchmark_plots + + +def domainlab_cli(): + """ + This is a copy of main_out.py (found outside of the domainlab directory), + so it can be run as a command line tool for the package installed with pip. + """ + args = parse_cmd_args() + if args.bm_dir: + aggregate_results.agg_main(args.bm_dir) + elif args.plot_data is not None: + gen_benchmark_plots(args.plot_data, args.outp_dir, + use_param_index=args.param_idx) + else: + set_seed(args.seed) + exp = Exp(args=args) + exp.execute() diff --git a/pyproject.toml b/pyproject.toml index ebe4a631d..66a35ff87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,10 +22,12 @@ scikit-learn = "^1.2.1" pyyaml = "^6.0" gdown = "^4.7.1" - [tool.poetry.dev-dependencies] pytest = "^6.2.5" +[tool.poetry.scripts] +domainlab = 'domainlab.cli:domainlab_cli' + [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" From 8431ad2f63abb057c56537e9e8265174a52284e1 Mon Sep 17 00:00:00 2001 From: agisga <11449372+agisga@users.noreply.github.com> Date: Thu, 11 Jan 2024 15:46:07 -0500 Subject: [PATCH 2/4] add tests for domainlab_cli --- domainlab/cli.py | 3 +-- main_out.py | 12 ++---------- tests/test_cli.py | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 tests/test_cli.py diff --git a/domainlab/cli.py b/domainlab/cli.py index e2e09282b..86b0db1ad 100644 --- a/domainlab/cli.py +++ b/domainlab/cli.py @@ -7,8 +7,7 @@ def domainlab_cli(): """ - This is a copy of main_out.py (found outside of the domainlab directory), - so it can be run as a command line tool for the package installed with pip. + Function used to run domainlab as a command line tool for the package installed with pip. """ args = parse_cmd_args() if args.bm_dir: diff --git a/main_out.py b/main_out.py index 76f4d69ec..471702f9b 100644 --- a/main_out.py +++ b/main_out.py @@ -1,17 +1,9 @@ from domainlab.arg_parser import parse_cmd_args +from domainlab.cli import domainlab_cli from domainlab.exp.exp_cuda_seed import set_seed # reproducibility from domainlab.exp.exp_main import Exp from domainlab.exp_protocol import aggregate_results from domainlab.utils.generate_benchmark_plots import gen_benchmark_plots if __name__ == "__main__": - args = parse_cmd_args() - if args.bm_dir: - aggregate_results.agg_main(args.bm_dir) - elif args.plot_data is not None: - gen_benchmark_plots(args.plot_data, args.outp_dir, - use_param_index=args.param_idx) - else: - set_seed(args.seed) - exp = Exp(args=args) - exp.execute() + domainlab_cli() diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 000000000..d07768c94 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,14 @@ +from importlib.metadata import entry_points + +from domainlab.cli import domainlab_cli + + +def test_entry_point(): + eps = entry_points() + cli_entry = eps.select(group='console_scripts')['domainlab'] + assert cli_entry.load() == domainlab_cli + +def test_domainlab_cli(monkeypatch): + test_args = ['--te_d', '1', '2', '--tr_d', '0', '3', '--task', 'mnistcolor10', '--epos', '500', '--bs', '16', '--model', 'erm', '--nname', 'conv_bn_pool_2', '--lr', '1e-3'] + monkeypatch.setattr('sys.argv', ['domainlab'] + test_args) + domainlab_cli() From 230986665de908c4a6a73aed2009552fc92f1f97 Mon Sep 17 00:00:00 2001 From: agisga <11449372+agisga@users.noreply.github.com> Date: Thu, 18 Jan 2024 15:21:05 -0500 Subject: [PATCH 3/4] attempt to run pytest via Poetry on CI --- .github/workflows/ci.yml | 7 +- poetry.lock | 147 ++++++++++++++++++++++++++++++++++++++- pyproject.toml | 8 ++- 3 files changed, 155 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a7adbd0b..4d6555f4d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,8 +26,13 @@ jobs: pip install -r requirements.txt pip install pytest pytest-cov pytest-shell python setup.py install + - name: Install Python Poetry + run: | + python -m pip install --upgrade pip + pip install poetry + poetry install --with dev - name: Generate coverage report - run: pytest --cov=domainlab tests/ --cov-report=xml + run: poetry run pytest --cov=domainlab tests/ --cov-report=xml - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 with: diff --git a/poetry.lock b/poetry.lock index cbea6fd67..2e8de781b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -78,6 +78,20 @@ mypy = ["contourpy[bokeh,docs]", "docutils-stubs", "mypy (==1.6.1)", "types-Pill test = ["Pillow", "contourpy[test-no-images]", "matplotlib"] test-no-images = ["pytest", "pytest-cov", "pytest-xdist", "wurlitzer"] +[[package]] +name = "coverage" +version = "7.4.0" +description = "Code coverage measurement for Python" +category = "dev" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.11.0a6\" and extra == \"toml\""} + +[package.extras] +toml = ["tomli"] + [[package]] name = "cycler" version = "0.12.1" @@ -171,6 +185,14 @@ category = "dev" optional = false python-versions = ">=3.7" +[[package]] +name = "itermate" +version = "1.0.2" +description = "Iterator-tools for functional programming." +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "joblib" version = "1.3.2" @@ -200,7 +222,7 @@ mdurl = ">=0.1,<1.0" [package.extras] benchmarking = ["psutil", "pytest", "pytest-benchmark"] -code_style = ["pre-commit (>=3.0,<4.0)"] +code-style = ["pre-commit (>=3.0,<4.0)"] compare = ["commonmark (>=0.9,<1.0)", "markdown (>=3.4,<4.0)", "mistletoe (>=1.0,<2.0)", "mistune (>=2.0,<3.0)", "panflute (>=2.3,<3.0)"] linkify = ["linkify-it-py (>=1,<3)"] plugins = ["mdit-py-plugins"] @@ -356,6 +378,32 @@ toml = "*" [package.extras] testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] +[[package]] +name = "pytest-cov" +version = "4.1.0" +description = "Pytest plugin for measuring coverage." +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +coverage = {version = ">=5.2.1", extras = ["toml"]} +pytest = ">=4.6" + +[package.extras] +testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtualenv"] + +[[package]] +name = "pytest-shell" +version = "0.3.2" +description = "A pytest plugin to help with testing shell scripts / black box commands" +category = "dev" +optional = false +python-versions = ">=3.7,<4.0" + +[package.dependencies] +where = ">=1.0.2,<2.0.0" + [[package]] name = "python-dateutil" version = "2.8.2" @@ -400,7 +448,7 @@ urllib3 = ">=1.21.1,<3" [package.extras] socks = ["PySocks (>=1.5.6,!=1.5.7)"] -use_chardet_on_py3 = ["chardet (>=3.0.2,<6)"] +use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "rich" @@ -503,6 +551,14 @@ category = "dev" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +[[package]] +name = "tomli" +version = "2.0.1" +description = "A lil' TOML parser" +category = "dev" +optional = false +python-versions = ">=3.7" + [[package]] name = "torch" version = "1.12.1" @@ -593,6 +649,17 @@ brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"] socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] zstd = ["zstandard (>=0.18.0)"] +[[package]] +name = "where" +version = "1.0.2" +description = "Locates absolute file paths like the Windows 'where' or the Linux 'which' utility.\nMakes use of the PATH variable and the current directory." +category = "dev" +optional = false +python-versions = "*" + +[package.dependencies] +itermate = "1.0.2" + [[package]] name = "zipp" version = "3.17.0" @@ -608,7 +675,7 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "6e2ad7be4452b5c8848cc727d230513839bfc5220fcd81c6de9b4bddb5b96889" +content-hash = "0c4a82b3972427fc7b1dc3f446e952ae46078d677fa57a8058b41106157c92d2" [metadata.files] atomicwrites = [ @@ -768,6 +835,60 @@ contourpy = [ {file = "contourpy-1.2.0-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:0d7e03c0f9a4f90dc18d4e77e9ef4ec7b7bbb437f7f675be8e530d65ae6ef956"}, {file = "contourpy-1.2.0.tar.gz", hash = "sha256:171f311cb758de7da13fc53af221ae47a5877be5a0843a9fe150818c51ed276a"}, ] +coverage = [ + {file = "coverage-7.4.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:36b0ea8ab20d6a7564e89cb6135920bc9188fb5f1f7152e94e8300b7b189441a"}, + {file = "coverage-7.4.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:0676cd0ba581e514b7f726495ea75aba3eb20899d824636c6f59b0ed2f88c471"}, + {file = "coverage-7.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d0ca5c71a5a1765a0f8f88022c52b6b8be740e512980362f7fdbb03725a0d6b9"}, + {file = "coverage-7.4.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a7c97726520f784239f6c62506bc70e48d01ae71e9da128259d61ca5e9788516"}, + {file = "coverage-7.4.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:815ac2d0f3398a14286dc2cea223a6f338109f9ecf39a71160cd1628786bc6f5"}, + {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:80b5ee39b7f0131ebec7968baa9b2309eddb35b8403d1869e08f024efd883566"}, + {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:5b2ccb7548a0b65974860a78c9ffe1173cfb5877460e5a229238d985565574ae"}, + {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:995ea5c48c4ebfd898eacb098164b3cc826ba273b3049e4a889658548e321b43"}, + {file = "coverage-7.4.0-cp310-cp310-win32.whl", hash = "sha256:79287fd95585ed36e83182794a57a46aeae0b64ca53929d1176db56aacc83451"}, + {file = "coverage-7.4.0-cp310-cp310-win_amd64.whl", hash = "sha256:5b14b4f8760006bfdb6e08667af7bc2d8d9bfdb648351915315ea17645347137"}, + {file = "coverage-7.4.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:04387a4a6ecb330c1878907ce0dc04078ea72a869263e53c72a1ba5bbdf380ca"}, + {file = "coverage-7.4.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ea81d8f9691bb53f4fb4db603203029643caffc82bf998ab5b59ca05560f4c06"}, + {file = "coverage-7.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:74775198b702868ec2d058cb92720a3c5a9177296f75bd97317c787daf711505"}, + {file = "coverage-7.4.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:76f03940f9973bfaee8cfba70ac991825611b9aac047e5c80d499a44079ec0bc"}, + {file = "coverage-7.4.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:485e9f897cf4856a65a57c7f6ea3dc0d4e6c076c87311d4bc003f82cfe199d25"}, + {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:6ae8c9d301207e6856865867d762a4b6fd379c714fcc0607a84b92ee63feff70"}, + {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:bf477c355274a72435ceb140dc42de0dc1e1e0bf6e97195be30487d8eaaf1a09"}, + {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:83c2dda2666fe32332f8e87481eed056c8b4d163fe18ecc690b02802d36a4d26"}, + {file = "coverage-7.4.0-cp311-cp311-win32.whl", hash = "sha256:697d1317e5290a313ef0d369650cfee1a114abb6021fa239ca12b4849ebbd614"}, + {file = "coverage-7.4.0-cp311-cp311-win_amd64.whl", hash = "sha256:26776ff6c711d9d835557ee453082025d871e30b3fd6c27fcef14733f67f0590"}, + {file = "coverage-7.4.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:13eaf476ec3e883fe3e5fe3707caeb88268a06284484a3daf8250259ef1ba143"}, + {file = "coverage-7.4.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:846f52f46e212affb5bcf131c952fb4075b55aae6b61adc9856222df89cbe3e2"}, + {file = "coverage-7.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:26f66da8695719ccf90e794ed567a1549bb2644a706b41e9f6eae6816b398c4a"}, + {file = "coverage-7.4.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:164fdcc3246c69a6526a59b744b62e303039a81e42cfbbdc171c91a8cc2f9446"}, + {file = "coverage-7.4.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:316543f71025a6565677d84bc4df2114e9b6a615aa39fb165d697dba06a54af9"}, + {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:bb1de682da0b824411e00a0d4da5a784ec6496b6850fdf8c865c1d68c0e318dd"}, + {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:0e8d06778e8fbffccfe96331a3946237f87b1e1d359d7fbe8b06b96c95a5407a"}, + {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a56de34db7b7ff77056a37aedded01b2b98b508227d2d0979d373a9b5d353daa"}, + {file = "coverage-7.4.0-cp312-cp312-win32.whl", hash = "sha256:51456e6fa099a8d9d91497202d9563a320513fcf59f33991b0661a4a6f2ad450"}, + {file = "coverage-7.4.0-cp312-cp312-win_amd64.whl", hash = "sha256:cd3c1e4cb2ff0083758f09be0f77402e1bdf704adb7f89108007300a6da587d0"}, + {file = "coverage-7.4.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:e9d1bf53c4c8de58d22e0e956a79a5b37f754ed1ffdbf1a260d9dcfa2d8a325e"}, + {file = "coverage-7.4.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:109f5985182b6b81fe33323ab4707011875198c41964f014579cf82cebf2bb85"}, + {file = "coverage-7.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3cc9d4bc55de8003663ec94c2f215d12d42ceea128da8f0f4036235a119c88ac"}, + {file = "coverage-7.4.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cc6d65b21c219ec2072c1293c505cf36e4e913a3f936d80028993dd73c7906b1"}, + {file = "coverage-7.4.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5a10a4920def78bbfff4eff8a05c51be03e42f1c3735be42d851f199144897ba"}, + {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:b8e99f06160602bc64da35158bb76c73522a4010f0649be44a4e167ff8555952"}, + {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:7d360587e64d006402b7116623cebf9d48893329ef035278969fa3bbf75b697e"}, + {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:29f3abe810930311c0b5d1a7140f6395369c3db1be68345638c33eec07535105"}, + {file = "coverage-7.4.0-cp38-cp38-win32.whl", hash = "sha256:5040148f4ec43644702e7b16ca864c5314ccb8ee0751ef617d49aa0e2d6bf4f2"}, + {file = "coverage-7.4.0-cp38-cp38-win_amd64.whl", hash = "sha256:9864463c1c2f9cb3b5db2cf1ff475eed2f0b4285c2aaf4d357b69959941aa555"}, + {file = "coverage-7.4.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:936d38794044b26c99d3dd004d8af0035ac535b92090f7f2bb5aa9c8e2f5cd42"}, + {file = "coverage-7.4.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:799c8f873794a08cdf216aa5d0531c6a3747793b70c53f70e98259720a6fe2d7"}, + {file = "coverage-7.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e7defbb9737274023e2d7af02cac77043c86ce88a907c58f42b580a97d5bcca9"}, + {file = "coverage-7.4.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a1526d265743fb49363974b7aa8d5899ff64ee07df47dd8d3e37dcc0818f09ed"}, + {file = "coverage-7.4.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bf635a52fc1ea401baf88843ae8708591aa4adff875e5c23220de43b1ccf575c"}, + {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:756ded44f47f330666843b5781be126ab57bb57c22adbb07d83f6b519783b870"}, + {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:0eb3c2f32dabe3a4aaf6441dde94f35687224dfd7eb2a7f47f3fd9428e421058"}, + {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:bfd5db349d15c08311702611f3dccbef4b4e2ec148fcc636cf8739519b4a5c0f"}, + {file = "coverage-7.4.0-cp39-cp39-win32.whl", hash = "sha256:53d7d9158ee03956e0eadac38dfa1ec8068431ef8058fe6447043db1fb40d932"}, + {file = "coverage-7.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:cfd2a8b6b0d8e66e944d47cdec2f47c48fef2ba2f2dff5a9a75757f64172857e"}, + {file = "coverage-7.4.0-pp38.pp39.pp310-none-any.whl", hash = "sha256:c530833afc4707fe48524a44844493f36d8727f04dcce91fb978c414a8556cc6"}, + {file = "coverage-7.4.0.tar.gz", hash = "sha256:707c0f58cb1712b8809ece32b68996ee1e609f71bd14615bd8f87a1293cb610e"}, +] cycler = [ {file = "cycler-0.12.1-py3-none-any.whl", hash = "sha256:85cef7cff222d8644161529808465972e51340599459b8ac3ccbac5a854e0d30"}, {file = "cycler-0.12.1.tar.gz", hash = "sha256:88bb128f02ba341da8ef447245a9e138fae777f6a23943da4540077d3601eb1c"}, @@ -836,6 +957,10 @@ iniconfig = [ {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, ] +itermate = [ + {file = "itermate-1.0.2-py2-none-any.whl", hash = "sha256:00308991e0fe54465e0e0fbec4d47180b4f6df0f26c1e5d2ce3641e3373f28a0"}, + {file = "itermate-1.0.2.zip", hash = "sha256:5ee758cbb363493156cee7a29effc2b148a1a19d2be3097e92fc824991901e2a"}, +] joblib = [ {file = "joblib-1.3.2-py3-none-any.whl", hash = "sha256:ef4331c65f239985f3f2220ecc87db222f08fd22097a3dd5698f693875f8cbb9"}, {file = "joblib-1.3.2.tar.gz", hash = "sha256:92f865e621e17784e7955080b6d042489e3b8e294949cc44c6eac304f59772b1"}, @@ -1148,6 +1273,14 @@ pytest = [ {file = "pytest-6.2.5-py3-none-any.whl", hash = "sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134"}, {file = "pytest-6.2.5.tar.gz", hash = "sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89"}, ] +pytest-cov = [ + {file = "pytest-cov-4.1.0.tar.gz", hash = "sha256:3904b13dfbfec47f003b8e77fd5b589cd11904a21ddf1ab38a64f204d6a10ef6"}, + {file = "pytest_cov-4.1.0-py3-none-any.whl", hash = "sha256:6ba70b9e97e69fcc3fb45bfeab2d0a138fb65c4d0d6a41ef33983ad114be8c3a"}, +] +pytest-shell = [ + {file = "pytest-shell-0.3.2.tar.gz", hash = "sha256:7e30cf518a5271328f25eaa9013e1639607f169d7396a4b85204a8b34dacbab1"}, + {file = "pytest_shell-0.3.2-py3-none-any.whl", hash = "sha256:f60716134fc30e2c1fe9facb9fe60121d18b4d7b95e692b2c6f29271350aa12b"}, +] python-dateutil = [ {file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"}, {file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"}, @@ -1281,6 +1414,10 @@ toml = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, ] +tomli = [ + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, +] torch = [ {file = "torch-1.12.1-cp310-cp310-manylinux1_x86_64.whl", hash = "sha256:9c038662db894a23e49e385df13d47b2a777ffd56d9bcd5b832593fab0a7e286"}, {file = "torch-1.12.1-cp310-cp310-manylinux2014_aarch64.whl", hash = "sha256:4e1b9c14cf13fd2ab8d769529050629a0e68a6fc5cb8e84b4a3cc1dd8c4fe541"}, @@ -1340,6 +1477,10 @@ urllib3 = [ {file = "urllib3-2.1.0-py3-none-any.whl", hash = "sha256:55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3"}, {file = "urllib3-2.1.0.tar.gz", hash = "sha256:df7aa8afb0148fa78488e7899b2c59b5f4ffcfa82e6c54ccb9dd37c1d7b52d54"}, ] +where = [ + {file = "where-1.0.2-py2.py3-none-any.whl", hash = "sha256:66abc8edf95be7516e949d08a771f25acacff708ef481618562ab484fe5bc63e"}, + {file = "where-1.0.2.zip", hash = "sha256:325ef3a492a26189a47819f7375bc146887d39edd36fce132e86514334803fb1"}, +] zipp = [ {file = "zipp-3.17.0-py3-none-any.whl", hash = "sha256:0e923e726174922dce09c53c59ad483ff7bbb8e572e00c7f7c46b88556409f31"}, {file = "zipp-3.17.0.tar.gz", hash = "sha256:84e64a1c28cf7e91ed2078bb8cc8c259cb19b76942096c8d7b84947690cabaf0"}, diff --git a/pyproject.toml b/pyproject.toml index 66a35ff87..16813df95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,12 +22,14 @@ scikit-learn = "^1.2.1" pyyaml = "^6.0" gdown = "^4.7.1" -[tool.poetry.dev-dependencies] -pytest = "^6.2.5" - [tool.poetry.scripts] domainlab = 'domainlab.cli:domainlab_cli' +[tool.poetry.group.dev.dependencies] +pytest = "^6.2.5" +pytest-cov = "^4.1.0" +pytest-shell = "^0.3.2" + [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" From 0845fb47ee2f90ee64c859d7e1fc202af4e90511 Mon Sep 17 00:00:00 2001 From: agisga <11449372+agisga@users.noreply.github.com> Date: Thu, 18 Jan 2024 16:22:17 -0500 Subject: [PATCH 4/4] fixes codacy issues --- domainlab/cli.py | 9 +++++++-- tests/test_cli.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/domainlab/cli.py b/domainlab/cli.py index 86b0db1ad..082287e0e 100644 --- a/domainlab/cli.py +++ b/domainlab/cli.py @@ -1,3 +1,7 @@ +""" +command-line interface (CLI) for the domainlab package +""" + from domainlab.arg_parser import parse_cmd_args from domainlab.exp.exp_cuda_seed import set_seed # reproducibility from domainlab.exp.exp_main import Exp @@ -13,8 +17,9 @@ def domainlab_cli(): if args.bm_dir: aggregate_results.agg_main(args.bm_dir) elif args.plot_data is not None: - gen_benchmark_plots(args.plot_data, args.outp_dir, - use_param_index=args.param_idx) + gen_benchmark_plots( + args.plot_data, args.outp_dir, use_param_index=args.param_idx + ) else: set_seed(args.seed) exp = Exp(args=args) diff --git a/tests/test_cli.py b/tests/test_cli.py index d07768c94..9d4d738e3 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,14 +1,52 @@ +""" +test 'domainlab' entry point +""" + from importlib.metadata import entry_points from domainlab.cli import domainlab_cli def test_entry_point(): + """ + Test the entry point for the 'domainlab' console script. + + This function retrieves all entry points and asserts that the 'domainlab' + entry point is correctly associated with the 'domainlab_cli' function. + """ eps = entry_points() - cli_entry = eps.select(group='console_scripts')['domainlab'] - assert cli_entry.load() == domainlab_cli + cli_entry = eps.select(group="console_scripts")["domainlab"] + assert cli_entry.load() is domainlab_cli + def test_domainlab_cli(monkeypatch): - test_args = ['--te_d', '1', '2', '--tr_d', '0', '3', '--task', 'mnistcolor10', '--epos', '500', '--bs', '16', '--model', 'erm', '--nname', 'conv_bn_pool_2', '--lr', '1e-3'] - monkeypatch.setattr('sys.argv', ['domainlab'] + test_args) + """ + Test the 'domainlab_cli' function by simulating command-line arguments. + + This function uses the 'monkeypatch' fixture to set the command-line + arguments for the 'domainlab_cli' function and then calls it to ensure + it processes the arguments correctly. The test arguments simulate a + representative command-line input for the 'domainlab' tool. + """ + test_args = [ + "--te_d", + "1", + "2", + "--tr_d", + "0", + "3", + "--task", + "mnistcolor10", + "--epos", + "500", + "--bs", + "16", + "--model", + "erm", + "--nname", + "conv_bn_pool_2", + "--lr", + "1e-3", + ] + monkeypatch.setattr("sys.argv", ["domainlab"] + test_args) domainlab_cli()