Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 600df51

Browse files
committed
Added unit tests and coverage.
1 parent a74f121 commit 600df51

5 files changed

Lines changed: 121 additions & 35 deletions

File tree

.coveragerc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[run]
2+
branch = true
3+
4+
[report]
5+
skip_covered = True
6+
skip_empty = True
7+
8+
[html]
9+
directory = .cov
10+
11+
[xml]
12+
output = coverage.xml

.travis.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
language: python
2+
python:
3+
- 3.8
24

35
install:
4-
- pip3 install -U -r requirements.txt
5-
6-
# if: tag IS present
6+
- pip3 install -U -r tests/requirements.txt
77

88
script:
9-
- python3 ./test/Application.py
9+
- echo "Python Code Coverage\n================================================================================"
10+
- coverage run --append -m unittest tests.unit.TerminalUI
11+
- coverage report && coverage xml
12+
- echo "Upload coverage results to Codacy..." && python-codacy-coverage -r coverage.xml
13+
- echo "Upload coverage results to CodeCov..." && codecov
14+
- echo "Python Unit Tests\n================================================================================"
15+
- python -m unittest tests.unit.TerminalUI
1016

1117
deploy:
1218
provider: pypi

tests/requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-r ../requirements.txt
2+
3+
# Coverage collection
4+
Coverage>=5.2.1
5+
6+
# Coverage upload tools
7+
codacy-coverage>=1.3.11
8+
codecov>=2.1.9

tests/unit/TerminalUI.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# EMACS settings: -*- tab-width: 2; indent-tabs-mode: t -*-
2+
# vim: tabstop=2:shiftwidth=2:noexpandtab
3+
# kate: tab-width 2; replace-tabs off; indent-width 2;
4+
# =============================================================================
5+
# _____ _ _ _ _ ___
6+
# _ __ _ |_ _|__ _ __ _ __ ___ (_)_ __ __ _| | | | |_ _|
7+
# | '_ \| | | || |/ _ \ '__| '_ ` _ \| | '_ \ / _` | | | | || |
8+
# | |_) | |_| || | __/ | | | | | | | | | | | (_| | | |_| || |
9+
# | .__/ \__, ||_|\___|_| |_| |_| |_|_|_| |_|\__,_|_|\___/|___|
10+
# |_| |___/
11+
# =============================================================================
12+
# Authors: Patrick Lehmann
13+
#
14+
# Python unittest: Testing the pyTerminalUI module
15+
#
16+
# Description:
17+
# ------------------------------------
18+
# TODO
19+
#
20+
# License:
21+
# ============================================================================
22+
# Copyright 2017-2020 Patrick Lehmann - Bötzingen, Germany
23+
# Copyright 2007-2016 Patrick Lehmann - Dresden, Germany
24+
#
25+
# Licensed under the Apache License, Version 2.0 (the "License");
26+
# you may not use this file except in compliance with the License.
27+
# You may obtain a copy of the License at
28+
#
29+
# http://www.apache.org/licenses/LICENSE-2.0
30+
#
31+
# Unless required by applicable law or agreed to in writing, software
32+
# distributed under the License is distributed on an "AS IS" BASIS,
33+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34+
# See the License for the specific language governing permissions and
35+
# limitations under the License.
36+
#
37+
# SPDX-License-Identifier: Apache-2.0
38+
# ============================================================================
39+
#
40+
"""
41+
pyAttributes
42+
############
43+
44+
:copyright: Copyright 2007-2020 Patrick Lehmann - Bötzingen, Germany
45+
:license: Apache License, Version 2.0
46+
"""
47+
from unittest import TestCase
48+
49+
from pyTerminalUI import LineTerminal
50+
51+
52+
if __name__ == "__main__":
53+
print("ERROR: you called a testcase declaration file as an executable module.")
54+
print("Use: 'python -m unitest <testcase module>'")
55+
exit(1)
56+
57+
58+
class Application(LineTerminal):
59+
def __init__(self):
60+
super().__init__(verbose=True, debug=True, quiet=False)
61+
62+
LineTerminal.FATAL_EXIT_CODE = 0
63+
64+
65+
class Terminal(TestCase):
66+
app : Application
67+
68+
def setUp(self) -> None:
69+
self.app = Application()
70+
71+
def test_Version(self):
72+
Application.versionCheck((3, 8, 0))
73+
74+
def test_Write(self):
75+
self.app.WriteQuiet("This is a quiet message.")
76+
self.app.WriteNormal("This is a normal message.")
77+
self.app.WriteInfo("This is a info message.")
78+
self.app.WriteDebug("This is a debug message.")
79+
self.app.WriteWarning("This is a warning message.")
80+
self.app.WriteError("This is an error message.")
81+
self.app.WriteFatal("This is a fatal message.", immediateExit=False)
Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@
1111
# =============================================================================
1212
# Authors: Patrick Lehmann
1313
#
14-
# Python module: A test application for pyTerminalUI.
14+
# Python unittest: Helper functions for unittests
1515
#
1616
# Description:
1717
# ------------------------------------
1818
# TODO
1919
#
2020
# License:
2121
# ============================================================================
22-
# Copyright 2017-2019 Patrick Lehmann - Bötzingen, Germany
22+
# Copyright 2017-2020 Patrick Lehmann - Bötzingen, Germany
23+
# Copyright 2007-2016 Patrick Lehmann - Dresden, Germany
2324
#
2425
# Licensed under the Apache License, Version 2.0 (the "License");
2526
# you may not use this file except in compliance with the License.
2627
# You may obtain a copy of the License at
2728
#
28-
# http://www.apache.org/licenses/LICENSE-2.0
29+
# http://www.apache.org/licenses/LICENSE-2.0
2930
#
3031
# Unless required by applicable law or agreed to in writing, software
3132
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -36,32 +37,10 @@
3637
# SPDX-License-Identifier: Apache-2.0
3738
# ============================================================================
3839
#
39-
import os
40-
import sys
41-
sys.path.insert(0, os.path.abspath('.'))
42-
sys.path.insert(0, os.path.abspath('..'))
40+
"""
41+
pyAttributes
42+
############
4343
44-
from pyTerminalUI import LineTerminal
45-
46-
47-
class Application(LineTerminal):
48-
def __init__(self):
49-
super().__init__(verbose=True, debug=True, quiet=False)
50-
51-
LineTerminal.FATAL_EXIT_CODE = 0
52-
53-
def run(self):
54-
self.WriteQuiet("This is a quiet message.")
55-
self.WriteNormal("This is a normal message.")
56-
self.WriteInfo("This is a info message.")
57-
self.WriteDebug("This is a debug message.")
58-
self.WriteWarning("This is a warning message.")
59-
self.WriteError("This is an error message.")
60-
self.WriteFatal("This is a fatal message.")
61-
62-
# entry point
63-
if __name__ == "__main__":
64-
Application.versionCheck((3,6,0))
65-
app = Application()
66-
app.run()
67-
app.exit()
44+
:copyright: Copyright 2007-2020 Patrick Lehmann - Bötzingen, Germany
45+
:license: Apache License, Version 2.0
46+
"""

0 commit comments

Comments
 (0)