Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
chore: drop support for Python 3.6 (#3)
Browse files Browse the repository at this point in the history
* chore: drop support for Python 3.6

* fix: corrects build
  • Loading branch information
Justintime50 authored Sep 21, 2021
1 parent 050d947 commit 7a8a94f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 31 deletions.
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
18 changes: 8 additions & 10 deletions diff_tool/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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,
Expand Down
11 changes: 5 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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',
)
1 change: 0 additions & 1 deletion test/files/file1.txt

This file was deleted.

1 change: 0 additions & 1 deletion test/files/file2.txt

This file was deleted.

30 changes: 19 additions & 11 deletions test/unit/test_diff.py
Original file line number Diff line number Diff line change
@@ -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 '<!DOCTYPE html' in result
Expand All @@ -30,7 +38,7 @@ def test_open_file():


def test_write_file():
with mock.patch('builtins.open', mock.mock_open()) as mocked_file:
with patch('builtins.open', mock_open()) as mocked_file:
DiffTool._write_file('file_content', 'test.txt')

mocked_file.assert_called_with('test.txt', 'w')

0 comments on commit 7a8a94f

Please sign in to comment.