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

ValeriyMenshikov / restcodegen / 19739786445

27 Nov 2025 02:37PM UTC coverage: 83.311% (-3.5%) from 86.838%
19739786445

Pull #9

github

web-flow
Merge 494573424 into 04717a691
Pull Request #9: Release/2.0.1

340 of 414 new or added lines in 10 files covered. (82.13%)

7 existing lines in 2 files now uncovered.

614 of 737 relevant lines covered (83.31%)

2.5 hits per line

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

70.59
/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)
3✔
15
    return bool(parsed.scheme) and bool(parsed.netloc)
3✔
16

17

18
def name_to_snake(string: str) -> str:
3✔
19
    translation_table = str.maketrans(
3✔
20
        {
21
            " ": "_",
22
            "/": "_",
23
            ".": "_",
24
            "-": "_",
25
            "~": "_",
26
            "{": None,
27
            "}": None,
28
            "[": None,
29
            "]": None,
30
            "&": "and",
31
        }
32
    )
33
    string = re.sub(r"([A-Z]+)([A-Z][a-z])", r"\1_\2", string)
3✔
34
    string = re.sub(r"([a-z\d])([A-Z])", r"\1_\2", string)
3✔
35
    return string.translate(translation_table).lower().strip("_")
3✔
36

37

38
def snake_to_camel(string: str) -> str:
3✔
39
    return FieldNameResolver().get_valid_name(string, upper_camel=True)
3✔
40

41

42
def rename_python_builtins(name: str) -> str:
3✔
UNCOV
43
    built_in_functions = set(dir(builtins)) | set(keyword.kwlist)
×
UNCOV
44
    if name in built_in_functions:
×
45
        return name + "_"
×
UNCOV
46
    return name
×
47

48

49
def create_and_write_file(file_path: Path, text: str | None = None) -> None:
3✔
50
    file_path.parent.mkdir(parents=True, exist_ok=True)
3✔
51
    if text:
3✔
52
        file_path.write_text(text, encoding="utf-8")
3✔
53

54

55
def run_command(command: str | list[str]) -> tuple[int, str | None]:
3✔
56
    if isinstance(command, list):
×
57
        result = run(command, shell=False, stderr=PIPE, text=True)
×
58
    else:
59
        result = run(command, shell=True, stderr=PIPE, text=True)  # noqa: S602
×
60
    stderr = result.stderr
×
61
    return result.returncode, stderr
×
62

63

64
def format_file(output_dir: str | None = None) -> None:
3✔
65
    target = output_dir if output_dir is not None else "./clients/http"
×
66
    command_format = ["ruff", "format", target]
×
67
    run_command(command_format)
×
68
    command_check = ["ruff", "check", target, "--fix"]
×
69
    run_command(command_check)
×
70

71

72
@cache
3✔
73
def get_dependencies() -> list[dict[str, str]]:
3✔
74
    deps = [{"path": dep.name, "version": dep.version} for dep in importlib.metadata.distributions()]  # type: ignore[attr-defined]
3✔
75

76
    return sorted(deps, key=lambda x: x["path"].lower())
3✔
77

78

79
@cache
3✔
80
def get_version() -> str:
3✔
81
    deps = get_dependencies()
3✔
82
    for dep in deps:
3✔
83
        if dep["path"] == "restcodegen":
3✔
84
            return dep["version"]
3✔
85
    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