Skip to content

Commit cbe0972

Browse files
committed
Improve test coverage.
1 parent b2e9f6f commit cbe0972

File tree

8 files changed

+86
-14
lines changed

8 files changed

+86
-14
lines changed

domdf_python_tools/words.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
# this package
4747
import domdf_python_tools
48-
from domdf_python_tools.compat import importlib_resources
48+
from domdf_python_tools.compat import PYPY, importlib_resources
4949
from domdf_python_tools.doctools import prettify_docstrings
5050

5151
__all__ = [
@@ -601,7 +601,7 @@ def __call__(self, n: int) -> str: # type: ignore
601601
:param n:
602602
"""
603603

604-
if platform.python_implementation() == "PyPy":
604+
elif PYPY: # pragma: no cover (!CPython)
605605

606606
def __init__(self, singular: str, plural: str):
607607
super().__init__(ngettext, singular, plural)

tests/test_compat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# this package
2+
from domdf_python_tools.compat import nullcontext
3+
4+
5+
def test_nullcontext():
6+
with nullcontext("foo") as f:
7+
assert f == "foo"
8+
9+
assert f == "foo"

tests/test_doctools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
# this package
1717
from domdf_python_tools import doctools
1818
from domdf_python_tools.bases import Dictable
19+
from domdf_python_tools.compat import PYPY
1920
from domdf_python_tools.doctools import (
20-
PYPY,
2121
base_int_docstrings,
2222
base_new_docstrings,
2323
container_docstrings,

tests/test_iterative.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def test_make_tree(file_regression: FileRegressionFixture):
147147
],
148148
"msgpack>=0.5.2",
149149
],
150-
]
150+
],
151+
"domdf_python_tools==2.2.0",
151152
])
152153
),
153154
file_regression
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
└── apeye>=0.3.0
2-
├── appdirs>=1.4.4
3-
└── cachecontrol[filecache]>=0.12.6
4-
├── requests
5-
│ ├── chardet<4,>=3.0.2
6-
│ ├── idna<3,>=2.5
7-
│ ├── urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
8-
│ └── certifi>=2017.4.17
9-
└── msgpack>=0.5.2
1+
├── apeye>=0.3.0
2+
│ ├── appdirs>=1.4.4
3+
│ └── cachecontrol[filecache]>=0.12.6
4+
│ ├── requests
5+
│ │ ├── chardet<4,>=3.0.2
6+
│ │ ├── idna<3,>=2.5
7+
│ │ ├── urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
8+
│ │ └── certifi>=2017.4.17
9+
│ └── msgpack>=0.5.2
10+
└── domdf_python_tools==2.2.0

tests/test_paths.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,9 @@ def test_iterchildren_match(data_regression: DataRegressionFixture):
690690
repo_path = PathPlus(__file__).parent.parent
691691
assert repo_path.is_dir()
692692

693+
if (repo_path / "build").is_dir():
694+
shutil.rmtree(repo_path / "build")
695+
693696
children = list(repo_path.iterchildren(match="**/*.py"))
694697
assert children
695698

@@ -802,3 +805,40 @@ def test_iterchildren_no_exclusions(tmp_pathplus: PathPlus):
802805
)
803806
def test_globpath(pattern: str, filename: str, match: bool):
804807
assert matchglob(filename, pattern) is match
808+
809+
810+
def test_abspath(tmp_pathplus: PathPlus):
811+
assert (tmp_pathplus / "foo" / "bar" / "baz" / "..").abspath() == tmp_pathplus / "foo" / "bar"
812+
813+
file = tmp_pathplus / "foo" / "bar.py"
814+
file.parent.mkdir(parents=True)
815+
file.write_text("I'm the original")
816+
817+
link = tmp_pathplus / "baz.py"
818+
os.symlink(file, link)
819+
820+
assert link.read_text() == "I'm the original"
821+
assert link.is_symlink()
822+
assert link.resolve() == file
823+
assert link.abspath() == link
824+
825+
file.unlink()
826+
file.parent.rmdir()
827+
828+
assert isinstance((tmp_pathplus / "foo" / "bar" / "baz" / "..").abspath(), PathPlus)
829+
830+
831+
def test_abspath_dotted(tmp_pathplus: PathPlus):
832+
833+
file = tmp_pathplus / "baz.py"
834+
file.write_text("I'm the original")
835+
836+
link = tmp_pathplus / "bar" / "foo.py"
837+
link.parent.mkdir(parents=True)
838+
839+
os.symlink(os.path.join(link.parent, "..", "baz.py"), link)
840+
841+
assert link.read_text() == "I'm the original"
842+
assert link.is_symlink()
843+
assert link.resolve() == file
844+
assert link.abspath() == link

tests/test_paths_/test_iterchildren_match.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
- tests/mypy_test.py
6363
- tests/seq_tests.py
6464
- tests/test_bases.py
65+
- tests/test_compat.py
6566
- tests/test_dates.py
6667
- tests/test_delegators.py
6768
- tests/test_doctools.py

tests/test_stringlist.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
# this package
9-
from domdf_python_tools.stringlist import Indent, StringList
9+
from domdf_python_tools.stringlist import DelimitedList, Indent, StringList
1010

1111

1212
class TestStringList:
@@ -515,3 +515,23 @@ def test_eq(self):
515515
def test_pickle(self):
516516
indent = Indent(2, " ")
517517
assert indent == pickle.loads(pickle.dumps(indent)) # nosec: B301
518+
519+
520+
def test_delimitedlist():
521+
data = DelimitedList(['a', 'b', 'c', 'd', 'e'])
522+
523+
assert data.__format__(", ") == "a, b, c, d, e"
524+
assert data.__format__("; ") == "a; b; c; d; e"
525+
assert data.__format__(';') == "a;b;c;d;e"
526+
assert data.__format__('\n') == "a\nb\nc\nd\ne"
527+
528+
assert f"{data:, }" == "a, b, c, d, e"
529+
assert f"{data:; }" == "a; b; c; d; e"
530+
assert f"{data:;}" == "a;b;c;d;e"
531+
assert f"{data:\n}" == "a\nb\nc\nd\ne"
532+
533+
# TODO: this is a mypy issue
534+
assert f"{data:, }" == "a, b, c, d, e" # type: ignore
535+
assert f"{data:; }" == "a; b; c; d; e"
536+
assert f"{data:;}" == "a;b;c;d;e" # type: ignore
537+
assert f"{data:\n}" == "a\nb\nc\nd\ne" # type: ignore

0 commit comments

Comments
 (0)