Skip to content

Commit 5607d7b

Browse files
committed
Fix typos and cleaner code
1 parent 11a7d0e commit 5607d7b

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

usr/lib/python3/dist-packages/stdisplay/tests/__init__.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
class TestSTBase(unittest.TestCase):
2222
"""
2323
Base class for testing safe terminal utilities.
24+
25+
Assign "self.module" to the module you want to try on the "setup()" using
26+
"super()":
27+
28+
>>> class TestSTCat(stdisplay.tests.TestSTBase):
29+
>>> def setUp(self) -> None:
30+
>>> self.module = "stcat"
31+
>>> super().setUp()
2432
"""
2533

2634
def __init__(self, *args: Any, **kwargs: Any) -> None:
@@ -31,9 +39,8 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
3139
def setUp(self) -> None:
3240
self.tmpfiles_list = []
3341
contents = ["a b\n", "c d"]
34-
i = 0
3542
self.tmpdir = tempfile.mkdtemp()
36-
while i < 6:
43+
for i in range(0, 6):
3744
self.tmpfiles_list.append(os.path.join(self.tmpdir, str(i)))
3845
with open(self.tmpfiles_list[i], "w", encoding="utf-8") as file:
3946
if i == 0:
@@ -48,7 +55,6 @@ def setUp(self) -> None:
4855
pass
4956
file.flush()
5057
file.close()
51-
i += 1
5258
self.tmpfiles = {
5359
"empty": self.tmpfiles_list[0],
5460
"raw": self.tmpfiles_list[1],
@@ -91,11 +97,3 @@ def _test_util(
9197
module.main()
9298
result = str(stdout.getvalue()) # pylint: disable=no-member
9399
return result
94-
95-
def _get_file(self, file: str) -> str:
96-
"""
97-
Helper function get contents of a file.
98-
"""
99-
with open(file, mode="r", encoding="utf-8") as fileobj:
100-
text = fileobj.read()
101-
return text

usr/lib/python3/dist-packages/stdisplay/tests/stcatn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import stdisplay.tests
1111

1212

13-
class TestSTCat(stdisplay.tests.TestSTBase):
13+
class TestSTCatn(stdisplay.tests.TestSTBase):
1414
"""
1515
Test stcatn.
1616
"""

usr/lib/python3/dist-packages/stdisplay/tests/stprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class TestSTPrint(stdisplay.tests.TestSTBase):
1919
"""
20-
Test stecho.
20+
Test stprint.
2121
"""
2222

2323
def setUp(self) -> None:

usr/lib/python3/dist-packages/stdisplay/tests/stsponge.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
## SPDX-License-Identifier: AGPL-3.0-or-later
88

99
import unittest
10+
from pathlib import Path
1011
import stdisplay.tests
1112

1213

@@ -26,13 +27,13 @@ def test_stsponge(self) -> None:
2627
self.assertEqual("", self._test_util())
2728
self.assertEqual("", self._test_util(stdin=""))
2829
self.assertEqual("stdin", self._test_util(stdin="stdin"))
29-
# Empty stdin with file argument.
30+
# Empty stdin with file argument produces empty stdout and file.
3031
self.assertEqual("", self._test_util(argv=[self.tmpfiles["fill"]]))
3132
self.assertEqual(
3233
"",
33-
self._get_file(file=self.tmpfiles["fill"]),
34+
Path(self.tmpfiles["fill"]).read_text(encoding="utf-8"),
3435
)
35-
# Empty stdin when writing to file and file sanitization.
36+
# Empty stdout when writing to file and file sanitization.
3637
self.assertEqual(
3738
"",
3839
self._test_util(
@@ -41,9 +42,9 @@ def test_stsponge(self) -> None:
4142
)
4243
self.assertEqual(
4344
self.text_dirty_sanitized,
44-
self._get_file(file=self.tmpfiles["fill"]),
45+
Path(self.tmpfiles["fill"]).read_text(encoding="utf-8"),
4546
)
46-
# Empty stdin when writing to multiple files and its sanitization.
47+
# Empty stdout when writing to multiple files and its sanitization.
4748
self.assertEqual(
4849
"",
4950
self._test_util(
@@ -53,11 +54,11 @@ def test_stsponge(self) -> None:
5354
)
5455
self.assertEqual(
5556
self.text_dirty_sanitized,
56-
self._get_file(file=self.tmpfiles["fill"]),
57+
Path(self.tmpfiles["fill"]).read_text(encoding="utf-8"),
5758
)
5859
self.assertEqual(
5960
self.text_dirty_sanitized,
60-
self._get_file(file=self.tmpfiles["fill2"]),
61+
Path(self.tmpfiles["fill2"]).read_text(encoding="utf-8"),
6162
)
6263

6364

usr/lib/python3/dist-packages/stdisplay/tests/sttee.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
## SPDX-License-Identifier: AGPL-3.0-or-later
88

99
import unittest
10+
from pathlib import Path
1011
import stdisplay.tests
1112

1213

@@ -30,7 +31,7 @@ def test_sttee(self) -> None:
3031
self.assertEqual("", self._test_util(argv=[self.tmpfiles["fill"]]))
3132
self.assertEqual(
3233
"",
33-
self._get_file(file=self.tmpfiles["fill"]),
34+
Path(self.tmpfiles["fill"]).read_text(encoding="utf-8"),
3435
)
3536
# Stdin sanitization and writing to file.
3637
self.assertEqual(
@@ -41,7 +42,7 @@ def test_sttee(self) -> None:
4142
)
4243
self.assertEqual(
4344
self.text_dirty_sanitized,
44-
self._get_file(file=self.tmpfiles["fill"]),
45+
Path(self.tmpfiles["fill"]).read_text(encoding="utf-8"),
4546
)
4647
# Stdin sanitization and writing to multiple files.
4748
self.assertEqual(
@@ -53,11 +54,11 @@ def test_sttee(self) -> None:
5354
)
5455
self.assertEqual(
5556
self.text_dirty_sanitized,
56-
self._get_file(file=self.tmpfiles["fill"]),
57+
Path(self.tmpfiles["fill"]).read_text(encoding="utf-8"),
5758
)
5859
self.assertEqual(
5960
self.text_dirty_sanitized,
60-
self._get_file(file=self.tmpfiles["fill2"]),
61+
Path(self.tmpfiles["fill2"]).read_text(encoding="utf-8"),
6162
)
6263

6364

0 commit comments

Comments
 (0)