• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WenjieDu / PyPOTS / 6263888182

21 Sep 2023 03:34PM UTC coverage: 0.0% (-82.8%) from 82.803%
6263888182

Pull #190

github

WenjieDu
docs: update docs;
Pull Request #190: Add models US-GAN and GP-VAE, update docs, refactor testing cases, add cal_internal_cluster_validation_metrics()

492 of 492 new or added lines in 17 files covered. (100.0%)

0 of 4107 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pypots/cli/dev.py
1
"""
2
CLI tools to help the development team build PyPOTS.
3
"""
4

5
# Created by Wenjie Du <wenjay.du@gmail.com>
6
# License: GLP-v3
7

8
import os
×
9
import shutil
×
10
from argparse import Namespace
×
11

12
from .base import BaseCommand
×
13
from ..utils.logging import logger
×
14

15
IMPORT_ERROR_MESSAGE = (
×
16
    "`pypots-cli dev` command is for PyPOTS developers to run tests easily. "
17
    "Therefore, you need a complete PyPOTS development environment. However, you are missing some dependencies. "
18
    "Please refer to https://github.com/WenjieDu/PyPOTS/blob/main/environment-dev.yml for dependency details. "
19
)
20

21

22
def dev_command_factory(args: Namespace):
×
23
    return DevCommand(
×
24
        args.build,
25
        args.cleanup,
26
        args.run_tests,
27
        args.k,
28
        args.show_coverage,
29
        args.lint_code,
30
    )
31

32

33
class DevCommand(BaseCommand):
×
34
    """CLI tools helping develop PyPOTS. Easy the running of tests and code linting with Black and Flake8.
35

36
    Examples
37
    --------
38
    $ pypots-cli dev --run_tests
39
    $ pypots-cli dev --run_tests --show_coverage  # show code coverage
40
    $ pypots-cli dev --run_tests -k imputation  # only run tests cases of imputation models
41
    $ pypots-cli dev --lint_code  # use Black to reformat the code and apply Flake8 to lint code
42

43
    """
44

45
    @staticmethod
×
46
    def register_subcommand(parser):
47
        sub_parser = parser.add_parser(
×
48
            "dev",
49
            help="CLI tools helping develop PyPOTS code",
50
        )
51
        sub_parser.add_argument(
×
52
            "--build",
53
            dest="build",
54
            action="store_true",
55
            help="Build PyPOTS into a wheel and package the source code into a .tar.gz file for distribution",
56
        )
57
        sub_parser.add_argument(
×
58
            "-c",
59
            "--cleanup",
60
            dest="cleanup",
61
            action="store_true",
62
            help="Delete all caches and building files",
63
        )
64
        sub_parser.add_argument(
×
65
            "--run_tests",
66
            "--run-tests",
67
            dest="run_tests",
68
            action="store_true",
69
            help="Run all test cases",
70
        )
71
        sub_parser.add_argument(
×
72
            "--show-coverage",
73
            "--show_coverage",
74
            dest="show_coverage",
75
            action="store_true",
76
            help="Show the code coverage report after running tests",
77
        )
78
        sub_parser.add_argument(
×
79
            "-k",
80
            type=str,
81
            default=None,
82
            help="The -k option of pytest. Description of -k option in pytest: "
83
            "only run tests which match the given substring expression. An expression is a python evaluatable "
84
            "expression where all names are substring-matched against test names and their parent classes. "
85
            "Example: -k 'test_method or test_other' matches all test functions and classes whose name contains "
86
            "'test_method' or 'test_other', while -k 'not test_method' matches those that don't contain "
87
            "'test_method' in their names. -k 'not test_method and not test_other' will eliminate the matches. "
88
            "Additionally keywords are matched to classes and functions containing extra names in their "
89
            "'extra_keyword_matches' set, as well as functions which have names assigned directly to them. The "
90
            "matching is case-insensitive.",
91
        )
92
        sub_parser.add_argument(
×
93
            "--lint-code",
94
            "--lint_code",
95
            dest="lint_code",
96
            action="store_true",
97
            help="Run Black and Flake8 to lint code",
98
        )
99
        sub_parser.set_defaults(func=dev_command_factory)
×
100

101
    def __init__(
×
102
        self,
103
        build: bool,
104
        cleanup: bool,
105
        run_tests: bool,
106
        k: str,
107
        show_coverage: bool,
108
        lint_code: bool,
109
    ):
110
        self._build = build
×
111
        self._cleanup = cleanup
×
112
        self._run_tests = run_tests
×
113
        self._k = k
×
114
        self._show_coverage = show_coverage
×
115
        self._lint_code = lint_code
×
116

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

121
        if self._k is not None:
×
122
            assert self._run_tests, (
×
123
                "Argument `-k` should combine the use of `--run_tests`. "
124
                "Try `pypots-cli dev --run_tests -k your_pattern`"
125
            )
126

127
        if self._show_coverage:
×
128
            assert self._run_tests, (
×
129
                "Argument `--show_coverage` should combine the use of `--run_tests`. "
130
                "Try `pypots-cli dev --run_tests --show_coverage`"
131
            )
132

133
        if self._cleanup:
×
134
            assert not self._run_tests and not self._lint_code, (
×
135
                "Argument `--cleanup` should be used alone. "
136
                "Try `pypots-cli dev --cleanup`"
137
            )
138

139
    def run(self):
×
140
        """Execute the given command."""
141
        # run checks first
142
        self.checkup()
×
143

144
        try:
×
145
            if self._cleanup:
×
146
                shutil.rmtree("build", ignore_errors=True)
×
147
                shutil.rmtree("dist", ignore_errors=True)
×
148
                shutil.rmtree("pypots.egg-info", ignore_errors=True)
×
149
            elif self._build:
×
150
                self.execute_command("python setup.py sdist bdist bdist_wheel")
×
151
            elif self._run_tests:
×
152
                pytest_command = (
×
153
                    f"pytest -k {self._k}" if self._k is not None else "pytest"
154
                )
155
                command_to_run_test = (
×
156
                    f"coverage run -m {pytest_command}"
157
                    if self._show_coverage
158
                    else pytest_command
159
                )
160
                self.execute_command(command_to_run_test)
×
161
                if self._show_coverage and os.path.exists(".coverage"):
×
162
                    self.execute_command("coverage report -m")
×
163
            elif self._lint_code:
×
164
                logger.info("Reformatting with Black...")
×
165
                self.execute_command("black .")
×
166
                logger.info("Linting with Flake8...")
×
167
                self.execute_command("flake8 .")
×
168
        except ImportError:
×
169
            raise ImportError(IMPORT_ERROR_MESSAGE)
×
170
        except Exception as e:
×
171
            raise e
×
172
        finally:
173
            shutil.rmtree(".pytest_cache", ignore_errors=True)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc