Skip to content

Commit

Permalink
testing improved
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-mixas committed Oct 27, 2019
1 parent fb74c59 commit 03147f0
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 28 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
dist: xenial
language: python
python:
- '3.4'
- '3.5'
- '3.6'
- '3.7'
- '3.8'
- 'pypy3'
matrix:
include:
- python: 3.7
dist: xenial
install:
- pip install --quiet --upgrade coveralls pytest
script: coverage run --source nested_diff setup.py test
Expand Down
7 changes: 7 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[pytest]
addopts = -vv --flake8
testpaths = nested_diff tests

flake8-max-line-length = 79
flake8-ignore =
tests/* E501
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Libraries :: Python Modules',
Expand All @@ -34,7 +35,7 @@
packages=['nested_diff'],
test_suite='tests',
setup_requires=["pytest-runner"],
tests_require=['pytest', 'pyyaml'],
tests_require=['pytest', 'pytest-flake8', 'pyyaml'],
entry_points={
'console_scripts': [
'nested_diff=nested_diff.diff_tool:cli',
Expand Down
49 changes: 31 additions & 18 deletions tests/cli/diff_tool/test_diff_tool.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json
import pytest

from unittest import mock

from nested_diff.diff_tool import App as DiffApp
import nested_diff.diff_tool


def test_default_diff(capsys, expected, fullname):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('lists.a.json', shared=True),
fullname('lists.b.json', shared=True),
)).run()
Expand All @@ -19,7 +20,7 @@ def test_default_diff(capsys, expected, fullname):

def test_default_diff_with_tty(capsys, expected, fullname, stringio_tty):
with mock.patch('sys.stdout.isatty', return_value=True):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('lists.a.json', shared=True),
fullname('lists.b.json', shared=True),
)).run()
Expand All @@ -31,7 +32,7 @@ def test_default_diff_with_tty(capsys, expected, fullname, stringio_tty):


def test_enable_U_ops(capsys, expected, fullname):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('lists.a.json', shared=True),
fullname('lists.b.json', shared=True),
'--ofmt', 'json',
Expand All @@ -44,7 +45,7 @@ def test_enable_U_ops(capsys, expected, fullname):


def test_output_file(capsys, expected, fullname, testfile):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('lists.a.json', shared=True),
fullname('lists.b.json', shared=True),
'--ofmt', 'json',
Expand All @@ -59,7 +60,7 @@ def test_output_file(capsys, expected, fullname, testfile):


def test_json_ofmt_opts(capsys, expected, fullname):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('lists.a.json', shared=True),
fullname('lists.b.json', shared=True),
'--ofmt', 'json',
Expand All @@ -72,7 +73,7 @@ def test_json_ofmt_opts(capsys, expected, fullname):


def test_ini_ifmt(capsys, expected, fullname):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('lists.a.ini', shared=True),
fullname('lists.b.ini', shared=True),
'--ifmt', 'ini',
Expand All @@ -85,7 +86,7 @@ def test_ini_ifmt(capsys, expected, fullname):


def test_multiline_default(capsys, expected, fullname):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('multiline.a.json', shared=True),
fullname('multiline.b.json', shared=True),
)).run()
Expand All @@ -96,7 +97,7 @@ def test_multiline_default(capsys, expected, fullname):


def test_multiline_default_term(capsys, expected, fullname):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('multiline.a.json', shared=True),
fullname('multiline.b.json', shared=True),
'--ofmt', 'term',
Expand All @@ -108,7 +109,7 @@ def test_multiline_default_term(capsys, expected, fullname):


def test_multiline_context_0(capsys, expected, fullname):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('multiline.a.json', shared=True),
fullname('multiline.b.json', shared=True),
'--text-ctx', '0'
Expand All @@ -120,7 +121,7 @@ def test_multiline_context_0(capsys, expected, fullname):


def test_multiline_disabled(capsys, expected, fullname):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('multiline.a.json', shared=True),
fullname('multiline.b.json', shared=True),
'--text-ctx', '-1'
Expand All @@ -132,7 +133,7 @@ def test_multiline_disabled(capsys, expected, fullname):


def test_text_ofmt(capsys, expected, fullname):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('lists.a.json', shared=True),
fullname('lists.b.json', shared=True),
'--ofmt', 'text',
Expand All @@ -144,7 +145,7 @@ def test_text_ofmt(capsys, expected, fullname):


def test_term_ofmt(capsys, expected, fullname):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('lists.a.json', shared=True),
fullname('lists.b.json', shared=True),
'--ofmt', 'term',
Expand All @@ -156,7 +157,7 @@ def test_term_ofmt(capsys, expected, fullname):


def test_yaml_ifmt(capsys, expected, fullname):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('lists.a.yaml', shared=True),
fullname('lists.b.yaml', shared=True),
'--ifmt', 'yaml',
Expand All @@ -169,7 +170,7 @@ def test_yaml_ifmt(capsys, expected, fullname):


def test_yaml_ofmt(capsys, expected, fullname):
DiffApp(args=(
nested_diff.diff_tool.App(args=(
fullname('lists.a.json', shared=True),
fullname('lists.b.json', shared=True),
'--ofmt', 'yaml',
Expand All @@ -181,7 +182,7 @@ def test_yaml_ofmt(capsys, expected, fullname):


def test_exit_code_diff_absent(fullname):
code = DiffApp(args=(
code = nested_diff.diff_tool.App(args=(
fullname('lists.a.json', shared=True),
fullname('lists.a.json', shared=True),
)).run()
Expand All @@ -190,7 +191,7 @@ def test_exit_code_diff_absent(fullname):


def test_exit_code_diff_absent_U_opt_enabled(fullname):
code = DiffApp(args=(
code = nested_diff.diff_tool.App(args=(
fullname('lists.a.json', shared=True),
fullname('lists.a.json', shared=True),
'-U=1',
Expand All @@ -200,9 +201,21 @@ def test_exit_code_diff_absent_U_opt_enabled(fullname):


def test_exit_code_diff_present(fullname):
code = DiffApp(args=(
code = nested_diff.diff_tool.App(args=(
fullname('lists.a.json', shared=True),
fullname('lists.b.json', shared=True),
)).run()

assert code == 1


def test_entry_point(capsys):
with mock.patch('sys.argv', ['nested_diff', '-h']):
with pytest.raises(SystemExit) as e:
nested_diff.diff_tool.cli()

assert e.value.code == 0

captured = capsys.readouterr()
assert captured.out.startswith('usage: nested_diff [-h] [--version]')
assert '' == captured.err
25 changes: 20 additions & 5 deletions tests/cli/patch_tool/test_patch_tool.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import json
import pytest

from unittest import mock
from shutil import copyfile

from nested_diff.patch_tool import App as PatchApp
import nested_diff.patch_tool


def test_default_patch(capsys, content, fullname):
copyfile(
fullname('lists.a.json', shared=True),
fullname('got'),
)
PatchApp(args=(
nested_diff.patch_tool.App(args=(
fullname('got'),
fullname('lists.patch.json', shared=True),
)).run()
Expand All @@ -27,7 +30,7 @@ def test_json_ofmt_opts(capsys, content, expected, fullname):
fullname('lists.a.json', shared=True),
fullname('got'),
)
PatchApp(args=(
nested_diff.patch_tool.App(args=(
fullname('got'),
fullname('lists.patch.json', shared=True),
'--ofmt', 'json',
Expand All @@ -46,7 +49,7 @@ def test_yaml_ifmt(capsys, content, fullname):
fullname('lists.a.yaml', shared=True),
fullname('got'),
)
PatchApp(args=(
nested_diff.patch_tool.App(args=(
fullname('got'),
fullname('lists.patch.yaml', shared=True),
'--ifmt', 'yaml',
Expand All @@ -66,7 +69,7 @@ def test_yaml_ofmt(capsys, content, expected, fullname):
fullname('lists.a.json', shared=True),
fullname('got'),
)
PatchApp(args=(
nested_diff.patch_tool.App(args=(
fullname('got'),
fullname('lists.patch.json', shared=True),
'--ofmt', 'yaml',
Expand All @@ -77,3 +80,15 @@ def test_yaml_ofmt(capsys, content, expected, fullname):
assert '' == captured.err

assert expected == content(fullname('got'))


def test_entry_point(capsys):
with mock.patch('sys.argv', ['nested_patch', '-h']):
with pytest.raises(SystemExit) as e:
nested_diff.patch_tool.cli()

assert e.value.code == 0

captured = capsys.readouterr()
assert captured.out.startswith('usage: nested_patch [-h] [--version]')
assert '' == captured.err
9 changes: 9 additions & 0 deletions tests/test_fmt_text_multiline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
from nested_diff.fmt import TextFormatter


def test_equal():
a = 'A\nB\nC'
b = 'A\nB\nC'

got = TextFormatter().format(diff(a, b, U=False, multiline_diff_context=3))
print(got)
assert '' == got


def test_line_added():
a = 'B\nC'
b = 'A\nB\nC'
Expand Down

0 comments on commit 03147f0

Please sign in to comment.