Skip to content

Commit 3218e59

Browse files
authored
Add integration tests, using real CLI (#47)
1 parent 09c6832 commit 3218e59

File tree

4 files changed

+39
-57
lines changed

4 files changed

+39
-57
lines changed

.github/workflows/test.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ jobs:
3939
pip install .
4040
4141
- name: Run tests
42-
run: python test_eradicate.py
42+
run: |
43+
python test_eradicate.py
44+
# Integration:
45+
python -m eradicate setup.py
46+
eradicate setup.py
4347
4448
4549
coverage:
@@ -61,6 +65,7 @@ jobs:
6165
coverage run --include='eradicate.py,test_eradicate.py' test_eradicate.py
6266
coverage report --show-missing
6367
68+
6469
windows:
6570
name: Tests with python ${{ matrix.python-version }} on Windows
6671
runs-on: windows-latest
@@ -81,7 +86,12 @@ jobs:
8186
run: python setup.py install
8287

8388
- name: Run tests
84-
run: python test_eradicate.py
89+
run: |
90+
python test_eradicate.py
91+
# Integration:
92+
python -m eradicate setup.py
93+
eradicate setup.py
94+
8595
8696
python2:
8797
name: Tests with python ${{ matrix.python-version }}
@@ -105,4 +115,8 @@ jobs:
105115
python setup.py install
106116
107117
- name: Run tests
108-
run: python test_eradicate.py
118+
run: |
119+
python test_eradicate.py
120+
# Integration:
121+
python -m eradicate setup.py
122+
eradicate setup.py

eradicate

Lines changed: 0 additions & 47 deletions
This file was deleted.

eradicate.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@
2727
import difflib
2828
import io
2929
import os
30+
import sys
3031
import re
3132
import tokenize
3233

34+
try:
35+
detect_encoding = tokenize.detect_encoding
36+
except AttributeError:
37+
from lib2to3.pgen2 import tokenize as lib2to3_tokenize
38+
detect_encoding = lib2to3_tokenize.detect_encoding
39+
3340
__version__ = '2.2.0'
3441

3542

@@ -213,8 +220,7 @@ def detect_encoding(self, filename):
213220
"""Return file encoding."""
214221
try:
215222
with open(filename, 'rb') as input_file:
216-
from lib2to3.pgen2 import tokenize as lib2to3_tokenize
217-
encoding = lib2to3_tokenize.detect_encoding(input_file.readline)[0]
223+
encoding = detect_encoding(input_file.readline)[0]
218224

219225
# Check for correctness of encoding.
220226
with self.open_with_encoding(filename, encoding) as input_file:
@@ -236,7 +242,7 @@ def update_whitelist(self, new_whitelist, extend_default=True):
236242
flags=re.IGNORECASE)
237243

238244

239-
def main(argv, standard_out, standard_error):
245+
def main(argv=sys.argv, standard_out=sys.stdout, standard_error=sys.stderr):
240246
"""Main entry point."""
241247
import argparse
242248
parser = argparse.ArgumentParser(description=__doc__, prog='eradicate')
@@ -292,5 +298,10 @@ def main(argv, standard_out, standard_error):
292298
except IOError as exception:
293299
print('{}'.format(exception), file=standard_error)
294300
change_or_error = True
301+
295302
if change_or_error and args.error:
296303
return 1
304+
305+
306+
if __name__ == '__main__':
307+
main()

test_eradicate.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,14 +552,18 @@ def test_end_to_end(self):
552552
# x * 3 == False
553553
# x is a variable
554554
""") as filename:
555-
process = subprocess.Popen([sys.executable,
556-
'./eradicate', filename],
557-
stdout=subprocess.PIPE, universal_newlines=True)
555+
process = subprocess.Popen([sys.executable, '-m'
556+
'eradicate', filename],
557+
stdout=subprocess.PIPE,
558+
stderr=subprocess.PIPE,
559+
universal_newlines=True)
560+
out, err = process.communicate()
558561
self.assertEqual("""\
559562
@@ -1,2 +1 @@
560563
-# x * 3 == False
561564
# x is a variable""",
562-
'\n'.join(process.communicate()[0].splitlines()[2:]))
565+
'\n'.join(out.splitlines()[2:]))
566+
self.assertEqual(err, '')
563567

564568
def test_whitelist(self):
565569
mock_update = mock.Mock()

0 commit comments

Comments
 (0)