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

msiemens / PyGitUp / 11195870461

05 Oct 2024 07:48PM UTC coverage: 93.052% (+0.02%) from 93.035%
11195870461

push

github

msiemens
fix: make `run_cmd` more robust

3 of 3 new or added lines in 1 file covered. (100.0%)

375 of 403 relevant lines covered (93.05%)

3.63 hits per line

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

90.91
/PyGitUp/utils.py
1
"""
2
Some simple, generic useful methods.
3
"""
4
import subprocess
4✔
5
import sys
4✔
6

7
from subprocess import DEVNULL
4✔
8

9

10
def find(seq, test):
4✔
11
    """ Return first item in sequence where test(item) == True """
12
    for item in seq:
4✔
13
        if test(item):
4✔
14
            return item
4✔
15

16

17
def uniq(seq):
4✔
18
    """ Return a copy of seq without duplicates. """
19
    seen = set()
4✔
20
    return [x for x in seq if str(x) not in seen and not seen.add(str(x))]
4✔
21

22

23
def execute(cmd, cwd=None):
4✔
24
    """ Execute a command and return it's output. """
25
    try:
4✔
26
        lines = subprocess \
4✔
27
            .check_output(cmd, cwd=cwd, stderr=DEVNULL) \
28
            .splitlines()
29
    except subprocess.CalledProcessError:
4✔
30
        return None
4✔
31
    else:
32
        if lines:
4✔
33
            return decode(lines[0].strip())
4✔
34
        else:
35
            return None
×
36

37

38
def decode(s):
4✔
39
    """
40
    Decode a string using the system encoding if needed (ie byte strings)
41
    """
42
    if isinstance(s, bytes):
4✔
43
        return s.decode(sys.getdefaultencoding())
4✔
44
    else:
45
        return s
×
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

© 2025 Coveralls, Inc