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

ValeriyMenshikov / restcodegen / 18805103363

25 Oct 2025 03:38PM UTC coverage: 63.12% (-1.5%) from 64.627%
18805103363

push

github

web-flow
Merge pull request #7 from ValeriyMenshikov/release/issue-5

Closes #5
Closes #6

22 of 58 new or added lines in 9 files covered. (37.93%)

8 existing lines in 4 files now uncovered.

433 of 686 relevant lines covered (63.12%)

1.89 hits per line

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

51.85
/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 | list[str]) -> tuple[int, str | None]:
3✔
NEW
46
    if isinstance(command, list):
×
NEW
47
        result = run(command, shell=False, stderr=PIPE, text=True)
×
48
    else:
NEW
49
        result = run(command, shell=True, stderr=PIPE, text=True)  # noqa: S602
×
50
    stderr = result.stderr
×
51
    return result.returncode, stderr
×
52

53

54
def format_file(output_dir: str | None = None) -> None:
3✔
NEW
55
    target = output_dir if output_dir is not None else "./clients/http"
×
NEW
56
    command_format = ["ruff", "format", target]
×
NEW
57
    run_command(command_format)
×
NEW
58
    command_check = ["ruff", "check", target, "--fix"]
×
NEW
59
    run_command(command_check)
×
60

61

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

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

68

69
@cache
3✔
70
def get_version() -> str:
3✔
71
    deps = get_dependencies()
×
72
    for dep in deps:
×
73
        if dep["path"] == "restcodegen":
×
74
            return dep["version"]
×
75
    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