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

WenjieDu / PyPOTS / 4675243164

pending completion
4675243164

Pull #48

github

GitHub
Merge fa08b17c4 into ce199d307
Pull Request #48: Add the lint-code workflow and pypots-cli to help development

62 of 62 new or added lines in 3 files covered. (100.0%)

2804 of 3336 relevant lines covered (84.05%)

0.84 hits per line

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

0.0
/pypots/utils/commands/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
from argparse import ArgumentParser, Namespace
×
10

11
from pypots.utils.commands import BaseCommand
×
12

13

14
def dev_command_factory(args: Namespace):
×
15
    return DevCommand(
×
16
        args.run_tests,
17
        args.k,
18
        args.show_coverage,
19
        args.lint_code,
20
    )
21

22

23
class DevCommand(BaseCommand):
×
24
    @staticmethod
×
25
    def register_subcommand(parser: ArgumentParser):
×
26
        train_parser = parser.add_parser("dev", help="CLI tool to help development ")
×
27
        train_parser.add_argument(
×
28
            "--run_tests",
29
            dest="run_tests",
30
            action="store_true",
31
            help="run all test cases",
32
        )
33
        train_parser.add_argument(
×
34
            "--show_coverage",
35
            dest="show_coverage",
36
            action="store_true",
37
            help="show the code coverage report after running tests",
38
        )
39
        train_parser.add_argument(
×
40
            "-k",
41
            type=str,
42
            default="",
43
            required=False,
44
            help="the -k option of pytest. Description of -k option in pytest: "
45
            "only run tests which match the given substring expression. An expression is a python evaluatable "
46
            "expression where all names are substring-matched against test names and their parent classes. "
47
            "Example: -k 'test_method or test_other' matches all test functions and classes whose name contains "
48
            "'test_method' or 'test_other', while -k 'not test_method' matches those that don't contain "
49
            "'test_method' in their names. -k 'not test_method and not test_other' will eliminate the matches. "
50
            "Additionally keywords are matched to classes and functions containing extra names in their "
51
            "'extra_keyword_matches' set, as well as functions which have names assigned directly to them. The "
52
            "matching is case-insensitive.",
53
        )
54
        train_parser.add_argument(
×
55
            "--lint_code",
56
            dest="lint_code",
57
            action="store_true",
58
            help="run Black and Flake8 to lint code",
59
        )
60
        train_parser.set_defaults(func=dev_command_factory)
×
61

62
    def __init__(
×
63
        self,
64
        run_tests: bool,
65
        k: str,
66
        show_coverage: bool,
67
        lint_code: bool,
68
    ):
69
        self._run_tests = run_tests
×
70
        self._k = k
×
71
        self._show_coverage = show_coverage
×
72
        self._lint_code = lint_code
×
73

74
    def run(self):
×
75
        print(f"current dir: {os.getcwd()}")
×
76

77
        if self._run_tests:
×
78
            try:
×
79
                pytest_command = f"pytest -k {self._k}" if self._k else "pytest"
×
80
                command_to_run_test = (
×
81
                    f"coverage run -m {pytest_command}"
82
                    if self._show_coverage
83
                    else pytest_command
84
                )
85

86
                os.system(command_to_run_test)
×
87
                if self._show_coverage:
×
88
                    os.system("coverage report -m")
×
89
                    os.system("rm -rf .coverage")
×
90
                else:
91
                    print(
×
92
                        "Omit the code coverage report. Enable it by using --show_coverage if in need."
93
                    )
94
                os.system("rm -rf .pytest_cache")
×
95

96
            except Exception as e:
×
97
                raise RuntimeError(e)
×
98
        elif self._lint_code:
×
99
            try:
×
100
                os.system("black .")
×
101
                os.system("flake8 .")
×
102
            except Exception as e:
×
103
                raise RuntimeError(e)
×
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

© 2025 Coveralls, Inc