Skip to content

Commit

Permalink
Edit Python module versions for development
Browse files Browse the repository at this point in the history
Pytest and Sphinx were updated.

The Pytest contains change for log formatting [1]. This
change affected the indention of the logs captured with
the 'caplog'. The Logger() tests evaluated the output of
the logger with indentions which failed. The test should
be now more generic since the indention of the captured
log is now removed from asserted output. This would have
likely failed also previously if the test case filename
or the number of digits for the row number where the log
is printed would have changed.

[1] pytest-dev/pytest#5311

Signed-off-by: Heikki Laaksonen <[email protected]>
  • Loading branch information
heilaaks committed Jun 12, 2019
1 parent 0416077 commit bad44fa
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 97 deletions.
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pyflakes = "==2.1.1"
logging-tree = "==1.8"
pytest-xdist = "==1.28.0"
sphinx-rtd-theme = "==0.4.3"
sphinx = "==2.0.1"
pytest = "==4.5.0"
sphinx = "==2.1.1"
pytest = "==4.6.3"
flake8 = "==3.7.7"
docker = "==4.0.1"
requests = "*"
Expand Down
104 changes: 50 additions & 54 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
extras_docs = (
'sphinx==1.8.5 ; python_version<="3.4"',
'sphinx==2.0.1 ; python_version>"3.4"',
'sphinx==2.1.1 ; python_version>"3.4"',
'sphinxcontrib-openapi==0.4.0',
'sphinx_rtd_theme==0.4.3',
'sphinx-autobuild==0.7.1'
Expand All @@ -56,12 +56,12 @@
'flake8==3.7.7',
'logging_tree==1.8',
'mock==3.0.5',
'pluggy==0.11.0',
'pluggy==0.12.0',
'pprintpp==0.4.0',
'pyflakes==2.1.1',
'pylint==1.9.4 ; python_version=="2.7.*"',
'pylint==2.3.1 ; python_version>"2.7"',
'pytest==4.5.0',
'pytest==4.6.3',
'pytest-cov==2.7.1',
'pytest-mock==1.10.4',
'pytest-xdist==1.28.0',
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class Helper(object):
\x1b[^m]*m # Match all ANSI escape sequences.
''', re.VERBOSE)

RE_MATCH_LEADING_WHITEPSACES = re.compile(r'''
\n\s+ # Match newline and all leading whitespaces after it.
''', re.VERBOSE)

@classmethod
def read_template(cls, filename):
"""Get default content template in text format.
Expand Down
85 changes: 47 additions & 38 deletions tests/test_ut_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from snippy.logger import Logger
from tests.lib.content import Field
from tests.lib.helper import Helper


class TestUtLogger(object):
Expand Down Expand Up @@ -674,49 +675,57 @@ def test_logger_017(caplog):
)]
output_p3 = (
"format database row:",
" [('0d364a0e-6b63-11e9-b176-2c4d54508088',",
" 'reference',",
" 'https://writingfordevelopers.substack.com/p/how-to-write-commit-messages\\n'",
" 'https://chris.beams.io/posts/git-commit/',",
" 'How to write commit messages',",
" '',",
" '',",
" 'git',",
" 'commit,git,howto,message,scm',",
" 'https://writingfordevelopers.substack.com/p/how-to-write-commit-messages\\n'",
" 'https://chris.beams.io/posts/git-commit/',",
" '',",
" '',",
" '',",
" '2018-06-22T13:10:33.295299+00:00',",
" '2018-06-27T10:10:16.553052+00:00',",
" '33da9768-1257-4419-b6df-881e19f07bbc',",
" '6d221115da7b95409c59164632893a57419666135c08151ddbf0be976f3b20a3')]"
"[('0d364a0e-6b63-11e9-b176-2c4d54508088',",
"'reference',",
"'https://writingfordevelopers.substack.com/p/how-to-write-commit-messages\\n'",
"'https://chris.beams.io/posts/git-commit/',",
"'How to write commit messages',",
"'',",
"'',",
"'git',",
"'commit,git,howto,message,scm',",
"'https://writingfordevelopers.substack.com/p/how-to-write-commit-messages\\n'",
"'https://chris.beams.io/posts/git-commit/',",
"'',",
"'',",
"'',",
"'2018-06-22T13:10:33.295299+00:00',",
"'2018-06-27T10:10:16.553052+00:00',",
"'33da9768-1257-4419-b6df-881e19f07bbc',",
"'6d221115da7b95409c59164632893a57419666135c08151ddbf0be976f3b20a3')]"
)
output_p2 = (
"format database row:",
" [('0d364a0e-6b63-11e9-b176-2c4d54508088',",
" 'reference',",
" 'https://writingfordevelopers.substack.com/p/how-to-write-commit-messages\\nhttps://chris.beams.io/posts/git-commit/',",
" 'How to write commit messages',",
" '',",
" '',",
" 'git',",
" 'commit,git,howto,message,scm',",
" 'https://writingfordevelopers.substack.com/p/how-to-write-commit-messages\\nhttps://chris.beams.io/posts/git-commit/',",
" '',",
" '',",
" '',",
" '2018-06-22T13:10:33.295299+00:00',",
" '2018-06-27T10:10:16.553052+00:00',",
" '33da9768-1257-4419-b6df-881e19f07bbc',",
" '6d221115da7b95409c59164632893a57419666135c08151ddbf0be976f3b20a3')]"
"[('0d364a0e-6b63-11e9-b176-2c4d54508088',",
"'reference',",
"'https://writingfordevelopers.substack.com/p/how-to-write-commit-messages\\nhttps://chris.beams.io/posts/git-commit/',",
"'How to write commit messages',",
"'',",
"'',",
"'git',",
"'commit,git,howto,message,scm',",
"'https://writingfordevelopers.substack.com/p/how-to-write-commit-messages\\nhttps://chris.beams.io/posts/git-commit/',",
"'',",
"'',",
"'',",
"'2018-06-22T13:10:33.295299+00:00',",
"'2018-06-27T10:10:16.553052+00:00',",
"'33da9768-1257-4419-b6df-881e19f07bbc',",
"'6d221115da7b95409c59164632893a57419666135c08151ddbf0be976f3b20a3')]"
)

# Log is pretty printed.
#
# The captured log is formatted to remove leading whitespaces in
# front of every row in the log. The Pytest changes the indenting
# of the log based a header for each log that is based on filename
# and line number. This makes the test output behave differently
# depending on this unit test filename and the line number where
# the logger.debug log. This is anomality is removed by removing
# the identation from captured log.
logger.debug('format database row:\n%s', row)

assert '\n'.join(output_p3) in caplog.text or '\n'.join(output_p2) in caplog.text
text = Helper.RE_MATCH_LEADING_WHITEPSACES.sub('\n', caplog.text)
assert '\n'.join(output_p3) in text or '\n'.join(output_p2) in text

caplog.clear()
Logger.configure({
Expand All @@ -726,11 +735,11 @@ def test_logger_017(caplog):
'quiet': False,
'very_verbose': False
})

output = (
"format database row:",
"[('0d364a0e-6b63-11e9-b176-2c4d54508088', 'reference', 'https://writingfordevelopers.substack.com/p/how-to-write-commit-messages\\nhttps://chris.beams.io/posts/git-commit/', 'How to write commit messages', '', '', 'git', 'commit,git,howto,message,scm', 'https://writingfordevelopers.substack.com/p/how-to-write-commit-messages\\nhttps://chris.beams.io/posts/git-commit/', '', '', '', '2018-06-22T13:10:33.295299+00:00', '2018-06-27T10:10:16.553052+00:00', '33da9768-1257-4419-b6df-881e19f07bbc', '6d221115da7b95409c59164632893a57419666135c08151ddbf0be976f3b20a3')]" # noqa pylint: disable=line-too-long
)
# Log is not pretty printed because JSON logs are actived.
logger.debug('format database row:\n%s', row)
assert '\n'.join(output) in caplog.text
text = Helper.RE_MATCH_LEADING_WHITEPSACES.sub('\n', caplog.text)
assert '\n'.join(output) in text

0 comments on commit bad44fa

Please sign in to comment.