Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit-test cases for pypots-cli #72

Merged
merged 35 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
56cf848
doc: update the documentation configs and doc itself;
WenjieDu Apr 19, 2023
3f5dd7d
fix: try to fix Makefile;
WenjieDu Apr 19, 2023
0d9c579
fix: fix `ModuleNotFoundError: No module named 'pypots'` and avoid PE…
WenjieDu Apr 19, 2023
e11a8d1
feat: update the dependencies;
WenjieDu Apr 19, 2023
ad63280
feat: update the dependencies;
WenjieDu Apr 19, 2023
b8ad123
feat: add readthedocs config file;
WenjieDu Apr 19, 2023
99228f0
fix: update readthedocs config file;
WenjieDu Apr 19, 2023
552cb8c
refactor: delete docs/requirements.txt;
WenjieDu Apr 19, 2023
d335a11
doc: remove inherited-members in docs;
WenjieDu Apr 19, 2023
6243359
doc: exclude normrnd in pypots.forecasting.bttf;
WenjieDu Apr 19, 2023
589f99d
fix: update readthedocs config file;
WenjieDu Apr 19, 2023
0b16044
fix: remove html to fix error `Invalid "formats": expected one of (ht…
WenjieDu Apr 19, 2023
97671aa
fix: disable fail_on_warning;
WenjieDu Apr 19, 2023
6d47de5
doc: try to remove `exclude-members`;
WenjieDu Apr 19, 2023
c772bee
Merge branch 'dev' into doc
WenjieDu Apr 19, 2023
43354f0
Merge branch 'dev' into doc
WenjieDu Apr 21, 2023
1c71f4b
doc: update README;
WenjieDu Apr 21, 2023
d3f9e31
doc: update badges in README;
WenjieDu Apr 21, 2023
098325d
Merge branch 'dev' into doc
WenjieDu Apr 22, 2023
057a853
refactor: move `pypots-cli` from pypots/utils/commands to pypots/cli;
WenjieDu Apr 22, 2023
7697237
feat: add test cases for pypots-cli;
WenjieDu Apr 22, 2023
48e4855
feat: add test_cli.py into the execution of workflow CI;
WenjieDu Apr 22, 2023
a51bd93
fix: raise RuntimeError when enable strict mode in check_if_under_roo…
WenjieDu Apr 22, 2023
83cbec9
fix: try to use environment-dev.yml for testing env building;
WenjieDu Apr 23, 2023
3352b89
fix: remove installed pypots but keep dependencies;
WenjieDu Apr 23, 2023
418108b
feat: update environment_for_conda_test.yml;
WenjieDu Apr 23, 2023
5096b53
fix: capture RuntimeError;
WenjieDu Apr 23, 2023
3a49bd6
fix: only run installation command again if necessary;
WenjieDu Apr 23, 2023
05b1e44
fix: implement time out with threading;
WenjieDu Apr 23, 2023
65ecc5a
fix: directly set SPHINX_APIDOC_OPTIONS with os.environ to avoid bugs…
WenjieDu Apr 23, 2023
93da28d
fix: append "+cpu" if torch is not cuda version;
WenjieDu Apr 23, 2023
1c6e7da
fix: `pip install -e` error on Windows platform;
WenjieDu Apr 23, 2023
dd10fde
fix: log and ignore error raised when testing on Windows;
WenjieDu Apr 23, 2023
fbd6ae6
fix: log and ignore error raised when testing on Windows;
WenjieDu Apr 23, 2023
17091ae
fix: remove raising RuntimeError;
WenjieDu Apr 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add test cases for pypots-cli;
  • Loading branch information
WenjieDu committed Apr 22, 2023
commit 769723741733d2db4551a2fc7938c987c566f43b
2 changes: 1 addition & 1 deletion pypots/cli/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __init__(

def checkup(self):
"""Run some checks on the arguments to avoid error usages"""
self.check_if_under_root_dir()
self.check_if_under_root_dir(strict=True)

if self._k is not None:
assert self._run_tests, (
Expand Down
2 changes: 1 addition & 1 deletion pypots/cli/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __init__(

def checkup(self):
"""Run some checks on the arguments to avoid error usages"""
self.check_if_under_root_dir()
self.check_if_under_root_dir(strict=True)

if self._cleanup:
assert not self._gene_rst and not self._gene_html and not self._view_doc, (
Expand Down
2 changes: 1 addition & 1 deletion pypots/cli/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(

def checkup(self):
"""Run some checks on the arguments to avoid error usages"""
self.check_if_under_root_dir()
self.check_if_under_root_dir(strict=True)

def run(self):
"""Execute the given command."""
Expand Down
160 changes: 160 additions & 0 deletions pypots/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
"""
Test cases for the functions and classes in package `pypots.cli`.
"""

# Created by Wenjie Du <[email protected]>
# License: GLP-v3

import os
import unittest
from argparse import Namespace
from copy import copy

from pypots.cli.dev import dev_command_factory
from pypots.cli.doc import doc_command_factory
from pypots.cli.env import env_command_factory
from pypots.utils.logging import logger

PROJECT_ROOT_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), "../../.."))


class TestPyPOTSCLIDev(unittest.TestCase):
# set up the default arguments
default_arguments = {
"build": False,
"cleanup": False,
"run_tests": False,
"k": None,
"show_coverage": False,
"lint_code": False,
}
# `pypots-cli dev` must run under the project root dir
os.chdir(PROJECT_ROOT_DIR)

def test_0_build(self):
arguments = copy(self.default_arguments)
arguments["build"] = True
args = Namespace(**arguments)
dev_command_factory(args).run()

logger.info("run again under a non-root dir")
try:
os.chdir(os.path.abspath(os.path.join(PROJECT_ROOT_DIR, "pypots")))
dev_command_factory(args).run()
except RuntimeError: # try to run under a non-root dir, so RuntimeError will be raised
pass
except Exception as e: # other exceptions will cause an error and result in failed testing
raise e
finally:
os.chdir(PROJECT_ROOT_DIR)

def test_1_run_tests(self):
arguments = copy(self.default_arguments)
arguments["run_tests"] = True
arguments["k"] = "try_to_find_a_non_existing_test_case"
args = Namespace(**arguments)
try:
dev_command_factory(args).run()
except RuntimeError: # try to find a non-existing test case, so RuntimeError will be raised
pass
except Exception as e: # other exceptions will cause an error and result in failed testing
raise e

# enable show_coverage and run again
arguments["show_coverage"] = True
args = Namespace(**arguments)
try:
dev_command_factory(args).run()
except RuntimeError: # try to find a non-existing test case, so RuntimeError will be raised
pass
except Exception as e: # other exceptions will cause an error and result in failed testing
raise e

def test_2_lint_code(self):
arguments = copy(self.default_arguments)
arguments["lint_code"] = True
args = Namespace(**arguments)
dev_command_factory(args).run()

def test_3_cleanup(self):
arguments = copy(self.default_arguments)
arguments["cleanup"] = True
args = Namespace(**arguments)
dev_command_factory(args).run()


class TestPyPOTSCLIDoc(unittest.TestCase):
# set up the default arguments
default_arguments = {
"gene_rst": False,
"branch": "main",
"gene_html": False,
"view_doc": True,
"port": 9075,
"cleanup": False,
}
# `pypots-cli doc` must run under the project root dir
os.chdir(PROJECT_ROOT_DIR)

def test_0_gene_rst(self):
arguments = copy(self.default_arguments)
arguments["gene_rst"] = True
arguments["branch"] = "dev"
args = Namespace(**arguments)
doc_command_factory(args).run()

logger.info("run again under a non-root dir")
try:
os.chdir(os.path.abspath(os.path.join(PROJECT_ROOT_DIR, "pypots")))
doc_command_factory(args).run()
except RuntimeError: # try to run under a non-root dir, so RuntimeError will be raised
pass
except Exception as e: # other exceptions will cause an error and result in failed testing
raise e
finally:
os.chdir(PROJECT_ROOT_DIR)

def test_1_gene_html(self):
arguments = copy(self.default_arguments)
arguments["gene_html"] = True
args = Namespace(**arguments)
doc_command_factory(args).run()

def test_2_view_doc(self):
arguments = copy(self.default_arguments)
arguments["view_doc"] = True
args = Namespace(**arguments)
doc_command_factory(args).run()

def test_3_cleanup(self):
arguments = copy(self.default_arguments)
arguments["cleanup"] = True
args = Namespace(**arguments)
doc_command_factory(args).run()


class TestPyPOTSCLIEnv(unittest.TestCase):
# set up the default arguments
default_arguments = {
"install": "optional",
"tool": "conda",
}

# `pypots-cli env` must run under the project root dir
os.chdir(PROJECT_ROOT_DIR)

def test_0_install_with_conda(self):
arguments = copy(self.default_arguments)
arguments["tool"] = "conda"
args = Namespace(**arguments)
env_command_factory(args).run()

def test_1_install_with_pip(self):
arguments = copy(self.default_arguments)
arguments["tool"] = "pip"
args = Namespace(**arguments)
env_command_factory(args).run()


if __name__ == "__main__":
unittest.main()