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

ValeriyMenshikov / restcodegen / 18804220065

25 Oct 2025 02:15PM UTC coverage: 64.531%. First build
18804220065

Pull #7

github

web-flow
Merge 443f98cb9 into 43edde1f5
Pull Request #7: Closes #5

20 of 34 new or added lines in 9 files covered. (58.82%)

433 of 671 relevant lines covered (64.53%)

1.94 hits per line

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

54.9
/restcodegen/generator/utils.py
1
import builtins
3✔
2
import importlib.metadata
3✔
3
import keyword
3✔
4
import re
3✔
5
from functools import cache
3✔
6
from pathlib import Path
3✔
7
from subprocess import PIPE, run
3✔
8
from urllib.parse import urlparse
3✔
9

10
from datamodel_code_generator.reference import FieldNameResolver
3✔
11

12

13
def is_url(path: str) -> bool:
3✔
14
    parsed = urlparse(path)
×
15
    return bool(parsed.scheme) and bool(parsed.netloc)
×
16

17

18
def name_to_snake(string: str) -> str:
3✔
19
    string = string.replace(" ", "_").replace("/", "_").replace(".", "_")
3✔
20
    string = string.replace("{", "").replace("}", "")
3✔
21
    string = re.sub(r"([A-Z]+)([A-Z][a-z])", r"\1_\2", string)
3✔
22
    string = re.sub(r"([a-z\d])([A-Z])", r"\1_\2", string)
3✔
23
    string = re.sub("&", "and", string)
3✔
24
    string = string.replace("-", "_").lower().strip("_")
3✔
25
    return string
3✔
26

27

28
def snake_to_camel(string: str) -> str:
3✔
29
    return FieldNameResolver().get_valid_name(string, upper_camel=True)
3✔
30

31

32
def rename_python_builtins(name: str) -> str:
3✔
33
    built_in_functions = set(dir(builtins)) | set(keyword.kwlist)
×
34
    if name in built_in_functions:
×
35
        return name + "_"
×
36
    return name
×
37

38

39
def create_and_write_file(file_path: Path, text: str | None = None) -> None:
3✔
40
    file_path.parent.mkdir(parents=True, exist_ok=True)
×
41
    if text:
×
42
        file_path.write_text(text, encoding="utf-8")
×
43

44

45
def run_command(command: str) -> tuple[int, str | None]:
3✔
46
    result = run(command, shell=True, stderr=PIPE, text=True)  # noqa: S602
×
47
    stderr = result.stderr
×
48
    return result.returncode, stderr
×
49

50

51
def format_file() -> None:
3✔
52
    command_format = [
×
53
        "ruff",
54
        "format",
55
        "./clients/http",
56
    ]
57
    run_command(" ".join(command_format))
×
58
    command_check = [
×
59
        "ruff",
60
        "check",
61
        "./clients/http",
62
        "--fix",
63
    ]
64
    run_command(" ".join(command_check))
×
65

66

67
@cache
3✔
68
def get_dependencies() -> list[dict[str, str]]:
3✔
NEW
69
    deps = [{"path": dep.name, "version": dep.version} for dep in importlib.metadata.distributions()]  # type: ignore[attr-defined]
×
70

71
    return sorted(deps, key=lambda x: x["path"].lower())
×
72

73

74
@cache
3✔
75
def get_version() -> str:
3✔
76
    deps = get_dependencies()
×
77
    for dep in deps:
×
78
        if dep["path"] == "restcodegen":
×
79
            return dep["version"]
×
80
    return "unknown"
×
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