Skip to content

Commit

Permalink
Added unit tests for empty refs and missing refsDecl printing in the…
Browse files Browse the repository at this point in the history
… console (#128)

* Added test for empty_refs

I still need to write unit tests for this test

* Added test for empty reference strings

Plus unit tests, changed to CHANGED.txt, and bumped version in setup.py

* Corrected a problem with one of the tests

Also deleted an old .rng kept just in case

* Updated tests to work with MyCapytain 2.0.8

* Changes to comply with MyCapytain 2.0.8

With unit test updates

* Updated CHANGES.md and bumped version number

* Added unit tests for empty refs and missing refsDecl printing in the console

* Forgot to fix one merge conflict
  • Loading branch information
sonofmun authored Jun 26, 2018
1 parent b1c4b0f commit c4b5fd7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.10 - 2018-06-26

- Added unit tests to make sure the empty references and MissingRefsDecl exceptions print in the console

## 1.1.9 - 2018-06-26

- Added tests for new EmptyRefsDecl exception
Expand Down
4 changes: 2 additions & 2 deletions HookTest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,11 @@ def end(self):
if empty_refs:
empty_refs = magenta('Empty references found:\n') + empty_refs + '\n'
else:
duplicate_nodes = forbidden_chars = dtd_errors = ''
duplicate_nodes = forbidden_chars = dtd_errors = empty_refs = ''

if capitains_errors:
capitains_errors = magenta('CapiTainS parsing errors found:\n') + capitains_errors + '\n'

print("{caps}{dupes}{forbs}{dtds}{empts}>>> End of the test !\n".format(caps=capitains_errors,
dupes=duplicate_nodes,
forbs=forbidden_chars,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='HookTest',
version="1.1.9",
version="1.1.10",
description='Hook Test Script for GitHub/CapiTainS repositories',
long_description=long_description,
url='http://github.com/Capitains/HookTest',
Expand Down
30 changes: 20 additions & 10 deletions tests/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import shutil
import os
import statistics
from colors import white, magenta, black


def unitlog_dict():
Expand Down Expand Up @@ -844,7 +845,7 @@ def test_end_with_counts(self, PTMock, printMock):
process.results["001"].additional['forbiddens'] = []
process.results["001"].additional['dtd_errors'] = []
process.results["001"].additional['language'] = 'UNK'
process.results["001"].additional['capitains_errors'] = []
process.results["001"].additional['capitains_errors'] = ["No reference declaration (refsDecl) found."]
process.results["001"].additional['empties'] = []
process.results["002"].units = {
"Metadata": True,
Expand All @@ -858,7 +859,7 @@ def test_end_with_counts(self, PTMock, printMock):
process.results["002"].additional['dtd_errors'] = ['error: value of attribute "cause" is invalid [In (L112 C52)]']
process.results["002"].additional['language'] = 'UNK'
process.results["002"].additional['capitains_errors'] = []
process.results["002"].additional['empties'] = []
process.results["002"].additional['empties'] = ["1 empty reference(s) at citation level 1"]
# add a unit where all tests fail
process.results['003'] = HookTest.test.UnitLog(
directory=".",
Expand Down Expand Up @@ -905,12 +906,16 @@ def test_end_with_counts(self, PTMock, printMock):
duplicate_nodes = '\x1b[35mDuplicate nodes found:\n\x1b[0m\t\x1b[35m002\x1b[0m\t1.1, 1.2\n\n'
forbidden_chars = '\x1b[35mForbidden characters found:\n\x1b[0m\t\x1b[35m002\x1b[0m\t1$1, 1-1\n\n'
dtd_errors = '\x1b[35mDTD errors found:\n\x1b[0m\t\x1b[35m002\x1b[0m\terror: value of attribute "cause" is invalid [In (L112 C52)]\n\n'
capitains_errors = magenta("CapiTainS parsing errors found:\n") + "\t" + magenta("001") + "\tNo reference declaration (refsDecl) found.\n\n"
empty_refs = magenta('Empty references found:\n') + "\t" + magenta("002") + "\t1 empty reference(s) at citation level 1\n\n"
printMock.assert_has_calls([
mock.call('', flush=True),
mock.call(InstanceMock, flush=True),
mock.call("{dupes}{forbs}{dtds}>>> End of the test !\n".format(dupes=duplicate_nodes,
forbs=forbidden_chars,
dtds=dtd_errors))
mock.call("{caps}{dupes}{forbs}{dtds}{empts}>>> End of the test !\n".format(caps=capitains_errors,
dupes=duplicate_nodes,
forbs=forbidden_chars,
dtds=dtd_errors,
empts=empty_refs))
], any_order=True)

@mock.patch("HookTest.test.print", create=True) # We patch and feed print to PrintMock
Expand Down Expand Up @@ -938,7 +943,7 @@ def test_end_not_verbose(self, PTMock, printMock):
process.results["001"].additional['duplicates'] = []
process.results["001"].additional['forbiddens'] = []
process.results["001"].additional['dtd_errors'] = []
process.results["001"].additional['capitains_errors'] = []
process.results["001"].additional['capitains_errors'] = ["No reference declaration (refsDecl) found."]
process.results["001"].additional['empties'] = []
process.results["002"].units = {
"Metadata": True,
Expand All @@ -950,7 +955,7 @@ def test_end_not_verbose(self, PTMock, printMock):
process.results["002"].additional['forbiddens'] = ['1$1', '1-1']
process.results["002"].additional['dtd_errors'] = ['error: value of attribute "cause" is invalid [In (L112 C52)]']
process.results["002"].additional['capitains_errors'] = []
process.results["002"].additional['empties'] = []
process.results["002"].additional['empties'] = ["1 empty reference(s) at citation level 1"]
# add a unit where all tests fail
process.results['003'] = HookTest.test.UnitLog(
directory=".",
Expand Down Expand Up @@ -995,12 +1000,17 @@ def test_end_not_verbose(self, PTMock, printMock):
duplicate_nodes = ''
forbidden_chars = ''
dtd_errors = ''
capitains_errors = magenta("CapiTainS parsing errors found:\n") + "\t" + magenta("001") + "\tNo reference declaration (refsDecl) found.\n\n"

empty_refs = ''
printMock.assert_has_calls([
mock.call('', flush=True),
mock.call(InstanceMock, flush=True),
mock.call("{dupes}{forbs}{dtds}>>> End of the test !\n".format(dupes=duplicate_nodes,
forbs=forbidden_chars,
dtds=dtd_errors))
mock.call("{caps}{dupes}{forbs}{dtds}{empts}>>> End of the test !\n".format(caps=capitains_errors,
dupes=duplicate_nodes,
forbs=forbidden_chars,
dtds=dtd_errors,
empts=empty_refs))
], any_order=True)

def test_manifest_build(self):
Expand Down

0 comments on commit c4b5fd7

Please sign in to comment.