Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests, using real CLI #47

Merged
merged 4 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ jobs:
pip install .

- name: Run tests
run: python test_eradicate.py
run: |
python test_eradicate.py
# Integration:
python -m eradicate setup.py
eradicate setup.py


coverage:
Expand All @@ -61,6 +65,7 @@ jobs:
coverage run --include='eradicate.py,test_eradicate.py' test_eradicate.py
coverage report --show-missing


windows:
name: Tests with python ${{ matrix.python-version }} on Windows
runs-on: windows-latest
Expand All @@ -81,7 +86,12 @@ jobs:
run: python setup.py install

- name: Run tests
run: python test_eradicate.py
run: |
python test_eradicate.py
# Integration:
python -m eradicate setup.py
eradicate setup.py


python2:
name: Tests with python ${{ matrix.python-version }}
Expand All @@ -105,4 +115,8 @@ jobs:
python setup.py install

- name: Run tests
run: python test_eradicate.py
run: |
python test_eradicate.py
# Integration:
python -m eradicate setup.py
eradicate setup.py
47 changes: 0 additions & 47 deletions eradicate

This file was deleted.

17 changes: 14 additions & 3 deletions eradicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@
import difflib
import io
import os
import sys
import re
import tokenize

try:
detect_encoding = tokenize.detect_encoding
except AttributeError:
from lib2to3.pgen2 import tokenize as lib2to3_tokenize
detect_encoding = lib2to3_tokenize.detect_encoding

__version__ = '2.2.0'


Expand Down Expand Up @@ -213,8 +220,7 @@ def detect_encoding(self, filename):
"""Return file encoding."""
try:
with open(filename, 'rb') as input_file:
from lib2to3.pgen2 import tokenize as lib2to3_tokenize
encoding = lib2to3_tokenize.detect_encoding(input_file.readline)[0]
encoding = detect_encoding(input_file.readline)[0]

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


def main(argv, standard_out, standard_error):
def main(argv=sys.argv, standard_out=sys.stdout, standard_error=sys.stderr):
"""Main entry point."""
import argparse
parser = argparse.ArgumentParser(description=__doc__, prog='eradicate')
Expand Down Expand Up @@ -292,5 +298,10 @@ def main(argv, standard_out, standard_error):
except IOError as exception:
print('{}'.format(exception), file=standard_error)
change_or_error = True

if change_or_error and args.error:
return 1


if __name__ == '__main__':
main()
12 changes: 8 additions & 4 deletions test_eradicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,18 @@ def test_end_to_end(self):
# x * 3 == False
# x is a variable
""") as filename:
process = subprocess.Popen([sys.executable,
'./eradicate', filename],
stdout=subprocess.PIPE, universal_newlines=True)
process = subprocess.Popen([sys.executable, '-m'
'eradicate', filename],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
out, err = process.communicate()
self.assertEqual("""\
@@ -1,2 +1 @@
-# x * 3 == False
# x is a variable""",
'\n'.join(process.communicate()[0].splitlines()[2:]))
'\n'.join(out.splitlines()[2:]))
self.assertEqual(err, '')

def test_whitelist(self):
mock_update = mock.Mock()
Expand Down