-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
NyanKiyoshi
committed
May 23, 2019
1 parent
8d1821a
commit ba4f3f7
Showing
6 changed files
with
120 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,26 @@ | ||
import pytest | ||
|
||
from pytest_django_queries.entry import flatten_entries | ||
|
||
pytest_plugins = 'pytester' | ||
|
||
|
||
@pytest.fixture | ||
def valid_comparison_entries(): | ||
left = { | ||
"test_module": { | ||
"test_improved_func": {"query-count": 20}, | ||
"test_degraded_func": {"query-count": 15}, | ||
"test_unchanged_func": {"query-count": 1}, | ||
} | ||
} | ||
|
||
right = { | ||
"test_module": { | ||
"test_improved_func": {"query-count": 19}, | ||
"test_degraded_func": {"query-count": 16}, | ||
"test_unchanged_func": {"query-count": 1}, | ||
} | ||
} | ||
|
||
return left, right |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
|
||
from click.testing import CliRunner | ||
from pytest_django_queries import cli | ||
|
||
|
||
def test_export_to_html_using_custom_template(testdir, valid_comparison_entries): | ||
left, right = valid_comparison_entries | ||
right["another_module"] = {"test_new_test": {"query-count": 1}} | ||
testdir.makefile('json', left=json.dumps(left)) | ||
testdir.makefile('json', right=json.dumps(right)) | ||
|
||
runner = CliRunner() | ||
result = runner.invoke(cli.main, ['diff', 'left.json', 'right.json']) | ||
assert result.exit_code == 0, result.stdout | ||
assert repr(result.stdout) == repr(u"""\ | ||
# another module | ||
test name \tleft count \tright count | ||
-------------------\t-----------\t----------- | ||
+ new test \t -\t 1 | ||
# module | ||
test name \tleft count \tright count | ||
-------------------\t-----------\t----------- | ||
- degraded func \t 15\t 16 | ||
+ improved func \t 20\t 19 | ||
unchanged func \t 1\t 1 | ||
""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import pytest | ||
|
||
from pytest_django_queries.diff import DiffGenerator | ||
from pytest_django_queries.entry import flatten_entries | ||
|
||
|
||
@pytest.mark.parametrize('right', ( | ||
{}, | ||
{"test_module": {}}, | ||
{"test_module_123": {}} | ||
)) | ||
def test_comparison_deleted_test_triggers_negative_review(right): | ||
left = flatten_entries({"test_module": {"test_deleted_func": {"query-count": 1}}}) | ||
right = flatten_entries(right) | ||
module_diffs = list(next(iter(DiffGenerator(left, right)))[1]) | ||
|
||
# We expect it to: | ||
# 1. start with '-' | ||
# 2. to give a left value of 1 | ||
# 3. to give a right value of N/A | ||
assert '- deleted func \t 1\t -' in module_diffs | ||
|
||
|
||
@pytest.mark.parametrize('left', ( | ||
{}, | ||
{"test_module": {}}, | ||
{"test_module_123": {}} | ||
)) | ||
def test_comparison_new_test_triggers_positive_review(left): | ||
left = flatten_entries(left) | ||
right = flatten_entries({"test_module": {"test_added_func": {"query-count": 1}}}) | ||
module_diffs = list(next(iter(DiffGenerator(left, right)))[1]) | ||
|
||
# We expect it to: | ||
# 1. start with '+' | ||
# 2. to give a left value of N/A | ||
# 3. to give a right value of 1 | ||
assert '+ added func \t -\t 1' in module_diffs | ||
|
||
|
||
def test_comparison_diff_is_correct(valid_comparison_entries): | ||
left, right = valid_comparison_entries | ||
left = flatten_entries(left) | ||
right = flatten_entries(right) | ||
|
||
module_diffs = list(next(iter(DiffGenerator(left, right)))[1]) | ||
|
||
assert len(module_diffs) == 4 # 3 tests + header | ||
assert '+ improved func \t 20\t 19' in module_diffs | ||
assert '- degraded func \t 15\t 16' in module_diffs | ||
assert ' unchanged func \t 1\t 1' in module_diffs |