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

dkrajzew / db2qthelp / 17189004596

24 Aug 2025 12:59PM UTC coverage: 96.223% (+3.1%) from 93.103%
17189004596

push

github

dkrajzew
patching tests

535 of 556 relevant lines covered (96.22%)

9.59 hits per line

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

98.25
/tests/util.py
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
"""grebakker - Utility functions for tests."""
4
# =============================================================================
5
__author__     = "Daniel Krajzewicz"
10✔
6
__copyright__  = "Copyright 2025, Daniel Krajzewicz"
10✔
7
__credits__    = ["Daniel Krajzewicz"]
10✔
8
__license__    = "GPLv3"
10✔
9
__version__    = "0.4.0"
10✔
10
__maintainer__ = "Daniel Krajzewicz"
10✔
11
__email__      = "daniel@krajzewicz.de"
10✔
12
__status__     = "Development"
10✔
13
# ===========================================================================
14
# - https://github.com/dkrajzew/db2qthelp
15
# - http://www.krajzewicz.de/docs/db2qthelp/index.html
16
# - http://www.krajzewicz.de
17
# ===========================================================================
18

19

20
# --- imports ---------------------------------------------------------------
21
import os
10✔
22
import shutil
10✔
23
import re
10✔
24
import json
10✔
25
import zipfile
10✔
26
import pathlib
10✔
27
import glob
10✔
28
from zipfile import ZipFile
10✔
29
TEST_PATH = os.path.split(__file__)[0]
10✔
30
import errno
10✔
31
from pathlib import Path
10✔
32

33

34

35
# --- imports ---------------------------------------------------------------
36
def pname(txt, path="<DIR>"):
10✔
37
    txt = txt.replace(str(path), "<DIR>").replace("\\", "/")
10✔
38
    txt = txt.replace("optional arguments", "options")
10✔
39
    return txt.replace("__main__.py", "db2qthelp").replace("pytest", "db2qthelp")
10✔
40

41
def tread(filepath):
10✔
42
    return filepath.read_text(encoding="utf-8")
×
43

44
def bread(filepath):
10✔
45
    return filepath.read_bytes()
10✔
46

47
def pdirtimename(txt, tmp_path):
10✔
48
    regex = r'([0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?'
10✔
49
    txt = txt.replace(str(tmp_path), "<DIR>").replace("\\", "/")
10✔
50
    txt = pname(txt)
10✔
51
    return re.sub(regex, "<DUR>", txt)
10✔
52

53
def copy_files(tmp_path, files):
10✔
54
    for file in files:
10✔
55
        if "*" not in file:
10✔
56
            shutil.copy(os.path.join(TEST_PATH, file), str(tmp_path / file))
10✔
57
            continue
10✔
58
        files2 = glob.glob(os.path.join(TEST_PATH, file))
10✔
59
        file_dir, _ = os.path.split(file)
10✔
60
        for file2 in files2:
10✔
61
            _, file2name = os.path.split(file2)
10✔
62
            src = os.path.join(TEST_PATH, file_dir, file2name)
10✔
63
            dst = tmp_path / file_dir / file2name
10✔
64
            shutil.copy(file2, dst)
10✔
65

66
def compare_files(tmp_path, folder, ext):
10✔
67
    seen = 0
10✔
68
    wrong = 0
10✔
69
    for file in os.listdir(os.path.join(tmp_path, folder)):
10✔
70
        if ext is not None:
10✔
71
            _, file_extension = os.path.splitext(file)
10✔
72
            if ext!=file_extension:
10✔
73
                continue
10✔
74
        orig = bread(Path(TEST_PATH) / folder / file)
10✔
75
        gen = bread(Path(tmp_path) / folder / file)
10✔
76
        if orig!=gen:
10✔
77
            wrong += 1 # pragma: no cover
78
            print(f"Mismatch for '{file}'") # pragma: no cover
79
            print(f"    '{Path(TEST_PATH) / folder / file}'") # pragma: no cover
80
            print(f"    '{Path(tmp_path) / folder / file}'") # pragma: no cover
81
        seen += 1
10✔
82
    return seen, wrong
10✔
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