Skip to content

Commit 2f52bba

Browse files
committed
refactor(tests): nuke sh dependency
Looks like `sh` is no longer compatible with PyPy2. I didn't particularly care to spend more than 15m figuring out why and using `sh` is a pointless crutch in the first place, so... bye!
1 parent 9f93bd8 commit 2f52bba

9 files changed

+49
-33
lines changed

.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ repos:
3131
args:
3232
- --max-line-length=79
3333
- --ignore-imports=yes
34+
- -d broad-except
3435
- -d fixme
3536
- -d import-error
3637
- -d invalid-name

coveralls/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def load_config_from_github():
9595
pr = None
9696
if os.environ.get('GITHUB_REF', '').startswith('refs/pull/'):
9797
pr = os.environ.get('GITHUB_REF', '//').split('/')[2]
98-
service_number += "-PR-{0}".format(pr)
98+
service_number += '-PR-{0}'.format(pr)
9999
return 'github', service_number, pr
100100

101101
@staticmethod

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
'docopt>=0.6.1',
3838
'requests>=1.0.0',
3939
],
40-
tests_require=['mock', 'pytest', 'sh>=1.08'],
40+
tests_require=['mock', 'pytest'],
4141
extras_require={
4242
'yaml': ['PyYAML>=3.10'],
4343
':python_version < "3"': ['urllib3[secure]'],

tests/api/configuration_test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import mock
99
import pytest
10-
import sh
1110
try:
1211
import yaml
1312
except ImportError:
@@ -22,7 +21,7 @@ class Configuration(unittest.TestCase):
2221
def setUp(self):
2322
self.dir = tempfile.mkdtemp()
2423

25-
sh.cd(self.dir)
24+
os.chdir(self.dir)
2625
with open('.coveralls.mock', 'w+') as fp:
2726
fp.write('repo_token: xxx\n')
2827
fp.write('service_name: jenkins\n')

tests/api/encoding_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import json
33
import logging
44
import os
5+
import subprocess
56
import sys
67

78
import coverage
89
import pytest
9-
import sh
1010

1111
from coveralls import Coveralls
1212

@@ -17,7 +17,7 @@
1717

1818
def test_non_unicode():
1919
os.chdir(NONUNICODE_DIR)
20-
sh.coverage('run', 'nonunicode.py')
20+
subprocess.call(['coverage', 'run', 'nonunicode.py'], cwd=NONUNICODE_DIR)
2121

2222
actual_json = json.dumps(Coveralls(repo_token='xxx').get_coverage())
2323
expected_json_part = (
@@ -32,7 +32,7 @@ def test_non_unicode():
3232
reason='coverage 4 not affected')
3333
def test_malformed_encoding_declaration(capfd):
3434
os.chdir(NONUNICODE_DIR)
35-
sh.coverage('run', 'malformed.py')
35+
subprocess.call(['coverage', 'run', 'malformed.py'], cwd=NONUNICODE_DIR)
3636

3737
logging.getLogger('coveralls').addHandler(logging.StreamHandler())
3838
assert Coveralls(repo_token='xxx').get_coverage() == []
@@ -46,7 +46,7 @@ def test_malformed_encoding_declaration(capfd):
4646
reason='coverage 3 fails')
4747
def test_malformed_encoding_declaration_py3_or_coverage4():
4848
os.chdir(NONUNICODE_DIR)
49-
sh.coverage('run', 'malformed.py')
49+
subprocess.call(['coverage', 'run', 'malformed.py'], cwd=NONUNICODE_DIR)
5050

5151
result = Coveralls(repo_token='xxx').get_coverage()
5252
assert len(result) == 1

tests/api/reporter_test.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# coding: utf-8
22
# pylint: disable=no-self-use
33
import os
4+
import subprocess
45
import unittest
56

6-
import sh
7-
87
from coveralls import Coveralls
98

109

@@ -23,11 +22,17 @@ class ReporterTest(unittest.TestCase):
2322
def setUp(self):
2423
os.chdir(EXAMPLE_DIR)
2524

26-
sh.rm('-f', '.coverage')
27-
sh.rm('-f', 'extra.py')
25+
try:
26+
os.remove('.coverage')
27+
except Exception:
28+
pass
29+
try:
30+
os.remove('extra.py')
31+
except Exception:
32+
pass
2833

2934
def test_reporter(self):
30-
sh.coverage('run', 'runtests.py')
35+
subprocess.call(['coverage', 'run', 'runtests.py'], cwd=EXAMPLE_DIR)
3136
results = Coveralls(repo_token='xxx').get_coverage()
3237
assert len(results) == 2
3338

@@ -59,7 +64,8 @@ def test_reporter(self):
5964
'coverage': [None, 1, None, 1, 1, 1, 1]})
6065

6166
def test_reporter_with_branches(self):
62-
sh.coverage('run', '--branch', 'runtests.py')
67+
subprocess.call(['coverage', 'run', '--branch', 'runtests.py'],
68+
cwd=EXAMPLE_DIR)
6369
results = Coveralls(repo_token='xxx').get_coverage()
6470
assert len(results) == 2
6571

@@ -98,13 +104,19 @@ def test_reporter_with_branches(self):
98104
'coverage': [None, 1, None, 1, 1, 1, 1]})
99105

100106
def test_missing_file(self):
101-
sh.echo('print("Python rocks!")', _out='extra.py')
102-
sh.coverage('run', 'extra.py')
103-
sh.rm('-f', 'extra.py')
107+
with open('extra.py', 'w') as f:
108+
f.write('print("Python rocks!")\n')
109+
subprocess.call(['coverage', 'run', 'extra.py'], cwd=EXAMPLE_DIR)
110+
try:
111+
os.remove('extra.py')
112+
except Exception:
113+
pass
104114
assert Coveralls(repo_token='xxx').get_coverage() == []
105115

106116
def test_not_python(self):
107-
sh.echo('print("Python rocks!")', _out='extra.py')
108-
sh.coverage('run', 'extra.py')
109-
sh.echo("<h1>This isn't python!</h1>", _out='extra.py')
117+
with open('extra.py', 'w') as f:
118+
f.write('print("Python rocks!")\n')
119+
subprocess.call(['coverage', 'run', 'extra.py'], cwd=EXAMPLE_DIR)
120+
with open('extra.py', 'w') as f:
121+
f.write("<h1>This isn't python!</h1>\n")
110122
assert Coveralls(repo_token='xxx').get_coverage() == []

tests/api/wear_test.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import coverage
99
import mock
1010
import pytest
11-
import sh
1211

1312
import coveralls
1413
from coveralls.api import log
@@ -23,7 +22,10 @@
2322
@mock.patch('coveralls.api.requests')
2423
class WearTest(unittest.TestCase):
2524
def setUp(self):
26-
sh.rm('-f', '.coverage')
25+
try:
26+
os.remove('.coverage')
27+
except Exception:
28+
pass
2729

2830
def test_wet_run(self, mock_requests):
2931
mock_requests.post.return_value.json.return_value = EXPECTED

tests/git_test.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import os
66
import re
77
import shutil
8+
import subprocess
89
import tempfile
910
import unittest
1011

1112
import mock
12-
import sh
1313

1414
import coveralls.git
1515

@@ -25,15 +25,18 @@ class GitTest(unittest.TestCase):
2525
def setUp(self):
2626
self.dir = tempfile.mkdtemp()
2727

28-
sh.cd(self.dir)
29-
sh.touch('README')
30-
31-
sh.git.init()
32-
sh.git.config('user.name', '"{}"'.format(GIT_NAME))
33-
sh.git.config('user.email', '"{}"'.format(GIT_EMAIL))
34-
sh.git.add('README')
35-
sh.git.commit('-m', GIT_COMMIT_MSG)
36-
sh.git.remote('add', GIT_REMOTE, GIT_URL)
28+
os.chdir(self.dir)
29+
open('README', 'a').close()
30+
31+
subprocess.call(['git', 'init'], cwd=self.dir)
32+
subprocess.call(['git', 'config', 'user.name',
33+
'"{}"'.format(GIT_NAME)], cwd=self.dir)
34+
subprocess.call(['git', 'config', 'user.email',
35+
'"{}"'.format(GIT_EMAIL)], cwd=self.dir)
36+
subprocess.call(['git', 'add', 'README'], cwd=self.dir)
37+
subprocess.call(['git', 'commit', '-m', GIT_COMMIT_MSG], cwd=self.dir)
38+
subprocess.call(['git', 'remote', 'add', GIT_REMOTE, GIT_URL],
39+
cwd=self.dir)
3740

3841
def tearDown(self):
3942
shutil.rmtree(self.dir)

tox.ini

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ usedevelop = true
1515
deps =
1616
mock
1717
pytest
18-
sh
1918
pyyaml: PyYAML>=3.10
2019
cov3: coverage<4.0
2120
cov4: coverage>=4.0,<4.1

0 commit comments

Comments
 (0)