From 7a8a94f1a9aca8ff9619c3c939a198fc4e29bfd5 Mon Sep 17 00:00:00 2001 From: Justin Hammond <39606064+Justintime50@users.noreply.github.com> Date: Tue, 21 Sep 2021 17:33:53 -0600 Subject: [PATCH] chore: drop support for Python 3.6 (#3) * chore: drop support for Python 3.6 * fix: corrects build --- .github/FUNDING.yml | 1 - .github/workflows/build.yml | 2 +- CHANGELOG.md | 6 ++++++ diff_tool/diff.py | 18 ++++++++---------- setup.py | 11 +++++------ test/files/file1.txt | 1 - test/files/file2.txt | 1 - test/unit/test_diff.py | 30 +++++++++++++++++++----------- 8 files changed, 39 insertions(+), 31 deletions(-) delete mode 100644 .github/FUNDING.yml delete mode 100644 test/files/file1.txt delete mode 100644 test/files/file2.txt diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 0b00509..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1 +0,0 @@ -github: [Justintime50] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e1749ee..26fc71b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - pythonversion: ["3.6", "3.7", "3.8", "3.9"] + pythonversion: ["3.7", "3.8", "3.9"] steps: - name: Checkout Repository uses: actions/checkout@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 8670630..98da004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## v2.3.0 (2021-09-20) + +* Drop support for Python 3.6 +* Replaces the `mock` library with the builtin `unittest.mock` library +* Reworks tests to use `io.StringIO()` instead of actual temp files + ## v2.2.0 (2021-04-12) * Fixed a bug when using this as a CLI tool and the tool wouldn't accept the path arguments (eg: TypeError: expected str, bytes or os.PathLike object, not TextIOWrapper) diff --git a/diff_tool/diff.py b/diff_tool/diff.py index 781fc68..98ea620 100644 --- a/diff_tool/diff.py +++ b/diff_tool/diff.py @@ -2,29 +2,29 @@ import difflib -class Cli(): +class Cli: def __init__(self): parser = argparse.ArgumentParser( - description='Display a diff between two files in HTML.' + description='Display a diff between two files in HTML.', ) parser.add_argument( '-f1', '--file1', required=True, - help='The path to the base file to compare a second file to.' + help='The path to the base file to compare a second file to.', ) parser.add_argument( '-f2', '--file2', required=True, - help='The path to the second file compared to the base file.' + help='The path to the second file compared to the base file.', ) parser.add_argument( '-o', '--output', required=False, default='diff.html', - help='The output to the output file including filename.' + help='The output to the output file including filename.', ) parser.parse_args(namespace=self) @@ -36,11 +36,10 @@ def run(self): ) -class DiffTool(): +class DiffTool: @staticmethod def run(file1, file2, output='diff.html'): - """Display a diff between two files in HTML. - """ + """Display a diff between two files in HTML.""" file1_content = DiffTool._open_file(file1) file2_content = DiffTool._open_file(file2) diff = DiffTool.generate_diff(file1_content, file2_content) @@ -49,8 +48,7 @@ def run(file1, file2, output='diff.html'): @staticmethod def generate_diff(file1, file2): - """Generate the content for the diff file - """ + """Generate the content for the diff file""" generated_diff = difflib.HtmlDiff().make_file( file1, file2, diff --git a/setup.py b/setup.py index a411632..a1af8b4 100644 --- a/setup.py +++ b/setup.py @@ -6,14 +6,13 @@ DEV_REQUIREMENTS = [ 'coveralls == 3.*', 'flake8', - 'mock == 4.*', 'pytest == 6.*', 'pytest-cov == 2.*', ] setuptools.setup( name='diff-tool', - version='2.2.0', + version='2.3.0', description='Display a diff between two files in HTML.', long_description=long_description, long_description_content_type="text/markdown", @@ -27,12 +26,12 @@ "Operating System :: OS Independent", ], extras_require={ - 'dev': DEV_REQUIREMENTS + 'dev': DEV_REQUIREMENTS, }, entry_points={ 'console_scripts': [ - 'diff-tool=diff_tool.diff:main' - ] + 'diff-tool=diff_tool.diff:main', + ], }, - python_requires='>=3.6', + python_requires='>=3.7', ) diff --git a/test/files/file1.txt b/test/files/file1.txt deleted file mode 100644 index e965047..0000000 --- a/test/files/file1.txt +++ /dev/null @@ -1 +0,0 @@ -Hello diff --git a/test/files/file2.txt b/test/files/file2.txt deleted file mode 100644 index 557db03..0000000 --- a/test/files/file2.txt +++ /dev/null @@ -1 +0,0 @@ -Hello World diff --git a/test/unit/test_diff.py b/test/unit/test_diff.py index 4d13da1..e673b78 100644 --- a/test/unit/test_diff.py +++ b/test/unit/test_diff.py @@ -1,23 +1,31 @@ -import mock +import io +from unittest.mock import mock_open, patch + from diff_tool import DiffTool -@mock.patch('diff_tool.diff.DiffTool._open_file') -@mock.patch('diff_tool.diff.DiffTool._write_file') +@patch('diff_tool.diff.DiffTool._open_file') +@patch('diff_tool.diff.DiffTool._write_file') def test_diff_run(mock_write, mock_open): - DiffTool.run( - 'setup.py', - 'README.md', - 'output.html' - ) + DiffTool.run('setup.py', 'README.md', 'output.html') + assert mock_open.call_count == 2 mock_write.assert_called_once() def test_generate_diff(): + """Here we create mocked files in memory and generate a diff + with their separate file content. + """ + file1 = io.StringIO() + file2 = io.StringIO() + + file1.write('Hello') + file2.write('Hello World') + result = DiffTool.generate_diff( - 'test/files/file1.txt', - 'test/files/file2.txt', + file1, + file2, ) assert '