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

unipoll / api / 6258866991

21 Sep 2023 08:02AM UTC coverage: 80.291% (-4.2%) from 84.442%
6258866991

push

github

web-flow
Merge pull request #61 from unipoll/development

Development merged

471 of 471 new or added lines in 42 files covered. (100.0%)

1874 of 2334 relevant lines covered (80.29%)

0.8 hits per line

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

45.45
/src/unipoll_api/utils/cli_args.py
1
import argparse
1✔
2
import textwrap
1✔
3
from dataclasses import dataclass
1✔
4

5

6
@dataclass
1✔
7
class Arguments:
1✔
8
    host: str
1✔
9
    port: int
1✔
10
    reload: bool
1✔
11

12

13
# Check if IP address is valid
14
def check_ip(arg_value):
1✔
15
    address = arg_value.split(".")
×
16
    if len(address) != 4:
×
17
        raise argparse.ArgumentTypeError("invalid host value")
×
18
    for i in address:
×
19
        if int(i) > 255 or int(i) < 0:
×
20
            raise argparse.ArgumentTypeError("invalid host value")
×
21
    return arg_value
×
22

23

24
# Parse CLI arguments
25
def parse_args() -> Arguments:
1✔
26
    # Create arg parser
27
    parser = argparse.ArgumentParser(
×
28
        formatter_class=argparse.RawDescriptionHelpFormatter,
29
        description=textwrap.dedent('''\
30
        Run University Polling API
31
        --------------------------------
32
        Examples:
33

34
            python main.py --reload --host=127.0.0.1 --port=8000
35
            python main.py --reload
36
        '''))
37

38
    parser.add_argument("--reload", action="store_true",
×
39
                        help="Enable auto-reload")
40
    parser.add_argument("--host", type=check_ip, default="127.0.0.1", help="Host IP address")
×
41
    parser.add_argument("--port", type=int, default=8000, help="Host port number")
×
42

43
    return Arguments(**vars(parser.parse_args()))
×
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