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

dfint / df-gettext-toolkit / 5870810915

pending completion
5870810915

push

github

insolor
Add refurb, fix its warnings

159 of 410 branches covered (38.78%)

Branch coverage included in aggregate %.

38 of 38 new or added lines in 14 files covered. (100.0%)

371 of 881 relevant lines covered (42.11%)

1.26 hits per line

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

0.0
/df_gettext_toolkit/csv_bisect/csv_bisect.py
1
import shutil
×
2
from pathlib import Path
×
3
from typing import List
×
4

5
from df_gettext_toolkit.utils import csv_utils
×
6
from df_gettext_toolkit.utils.backup import backup
×
7

8

9
def split_left(start, end):
×
10
    mid = (start + end) // 2
×
11
    return start, mid
×
12

13

14
def split_right(start, end):
×
15
    mid = (start + end) // 2
×
16
    return mid, end
×
17

18

19
def bisect(file_path: Path, encoding: str, data: List[List[str]]):
×
20
    def _bisect(start: int, end: int, bad: bool = False) -> bool:
×
21
        """
22
        returns:
23
        - True -> found
24
        - False -> not found
25
        """
26
        if start >= end:
×
27
            print("Empty slice, step back")
×
28
            return False
×
29

30
        print(f"From {start} to {end} (in total {end - start})")
×
31
        csv_utils.write_csv(file_path, encoding, data[start:end])
×
32

33
        if bad:
×
34
            confirmed = True
×
35
        else:
36
            confirmed = input("Is it bad (Y/N)? ").upper() == "Y"
×
37

38
        if not confirmed:
×
39
            return False
×
40

41
        if start == end - 1:
×
42
            print(f"Found string, line number {start+1}:")
×
43
            print(data[start])
×
44

45
            confirmed = input("Exclude from csv (Y/N)? ").upper() == "Y"
×
46
            if confirmed:
×
47
                csv_utils.write_csv(file_path, encoding, data[:start] + data[start + 1 :])
×
48

49
            return True
×
50

51
        print("Trying left half")
×
52
        result = _bisect(*split_left(start, end))
×
53
        if result:
×
54
            return result
×
55

56
        print("Trying right half")
×
57
        return _bisect(*split_right(start, end), bad=True)
×
58

59
    _bisect(0, len(data), bad=True)
×
60

61

62
def main(csv_file: Path, encoding: str):
×
63
    assert csv_file.is_file(), f"{csv_file.name} is not a file"
×
64

65
    try:
×
66
        with backup(csv_file, overwrite=True) as backup_path:
×
67
            data = list(csv_utils.read_csv(backup_path, encoding))
×
68
            bisect(csv_file, encoding, data)
×
69
    finally:
70
        confirmed = input("Restore from backup (Y/N)? ").upper() == "Y"
×
71
        if confirmed:
×
72
            shutil.copy(backup_path, csv_file)
×
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