aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2022-12-31 23:07:30 +0200
committerArthur Zamarin <arthurzam@gentoo.org>2022-12-31 23:07:30 +0200
commitd166566af2f2c84c061106986943c2cb872e7196 (patch)
treea56445bcc6440a950be4ce465722d5cb985cc745 /tests
parentstart work on 0.12.19 (diff)
downloadpkgcore-d166566af2f2c84c061106986943c2cb872e7196.tar.gz
pkgcore-d166566af2f2c84c061106986943c2cb872e7196.tar.bz2
pkgcore-d166566af2f2c84c061106986943c2cb872e7196.zip
properly close open file handlers during tests
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/ebuild/test_domain.py8
-rw-r--r--tests/ebuild/test_repo_objs.py8
-rw-r--r--tests/fs/test_fs.py3
-rw-r--r--tests/fs/test_livefs.py3
-rw-r--r--tests/pkgsets/test_filelist.py17
5 files changed, 17 insertions, 22 deletions
diff --git a/tests/ebuild/test_domain.py b/tests/ebuild/test_domain.py
index 90594b9d..28706e25 100644
--- a/tests/ebuild/test_domain.py
+++ b/tests/ebuild/test_domain.py
@@ -37,8 +37,8 @@ class TestDomain:
# assert the base state; no files, no content.
assert () == self.mk_domain().pkg_use
- open(self.pusedir / "00", "w").write("*/* X")
- open(self.pusedir / "01", "w").write("*/* -X Y")
+ (self.pusedir / "00").write_text("*/* X")
+ (self.pusedir / "01").write_text("*/* -X Y")
# Force the returned ordering to be reversed; this is to assert that
# the domain forces a sort.
@@ -56,7 +56,7 @@ class TestDomain:
) == self.mk_domain().pkg_use
def test_use_expand_syntax(self):
- open(self.pusedir / "a", "w").write(
+ (self.pusedir / "a").write_text(
textwrap.dedent(
"""
*/* x_y1
@@ -81,7 +81,7 @@ class TestDomain:
) == self.mk_domain().pkg_use
def test_use_flag_parsing_enforcement(self):
- open(self.pusedir / "a", "w").write("*/* X:")
+ (self.pusedir / "a").write_text("*/* X:")
# TODO: need to catch the warning here, but I'm not sure how.
# Meanwhile, ensure that the failed token is ignored.
assert ((packages.AlwaysTrue, ((), ())),) == self.mk_domain().pkg_use
diff --git a/tests/ebuild/test_repo_objs.py b/tests/ebuild/test_repo_objs.py
index 3babe3a1..f86f8fe0 100644
--- a/tests/ebuild/test_repo_objs.py
+++ b/tests/ebuild/test_repo_objs.py
@@ -48,7 +48,7 @@ class TestMetadataXml:
ls = f"<longdescription>{longdescription}</longdescription>\n"
sa = "<stabilize-allarches/>" if stabilize_allarches else ""
s = f"""<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
{cs}{ms}{us}{ls}{sa}</pkgmetadata>"""
return repo_objs.MetadataXml(data_source(s.encode("utf-8")))
@@ -155,11 +155,9 @@ Blake-light tragedy among the scholars of war.
def test_stabilize_allarches(self):
# missing
- assert False == self.get_metadata_xml().stabilize_allarches
+ assert not self.get_metadata_xml().stabilize_allarches
# present
- assert (
- True == self.get_metadata_xml(stabilize_allarches=True).stabilize_allarches
- )
+ assert self.get_metadata_xml(stabilize_allarches=True).stabilize_allarches
class TestProjectsXml:
diff --git a/tests/fs/test_fs.py b/tests/fs/test_fs.py
index d29b58c1..605be48f 100644
--- a/tests/fs/test_fs.py
+++ b/tests/fs/test_fs.py
@@ -106,7 +106,8 @@ class Test_fsFile(base):
o = self.make_obj(__file__)
with open(__file__) as f:
raw_data = f.read()
- assert o.data.text_fileobj().read() == raw_data
+ with o.data.text_fileobj() as f:
+ assert f.read() == raw_data
o = self.make_obj(
"/bin/this-file-should-not-exist-nor-be-read", data=data_source(raw_data)
diff --git a/tests/fs/test_livefs.py b/tests/fs/test_livefs.py
index f6fe28d0..3dbad612 100644
--- a/tests/fs/test_livefs.py
+++ b/tests/fs/test_livefs.py
@@ -29,7 +29,8 @@ class TestFsObjs:
assert o.location, "/tmp/etc/passwd"
assert o.data.path, "/etc/passwd"
with open("/etc/passwd", "rb") as f:
- assert o.data.bytes_fileobj().read(), f.read()
+ with o.data.bytes_fileobj() as fileobj:
+ assert fileobj.read() == f.read()
def test_gen_obj_reg(self, tmp_path):
(path := tmp_path / "reg_obj").touch()
diff --git a/tests/pkgsets/test_filelist.py b/tests/pkgsets/test_filelist.py
index 5f34e139..74158c2e 100644
--- a/tests/pkgsets/test_filelist.py
+++ b/tests/pkgsets/test_filelist.py
@@ -47,17 +47,12 @@ class TestFileList:
assert {
atom(line) for line in (tmp_path / "file").read_text().splitlines()
- } == set(
- map(
- atom,
- (
- "dev-util/diffball",
- "=dev-util/bsdiff-0.4",
- "dev-util/foon",
- "=dev-util/lib-1",
- ),
- )
- )
+ } == {
+ atom("dev-util/diffball"),
+ atom("=dev-util/bsdiff-0.4"),
+ atom("dev-util/foon"),
+ atom("=dev-util/lib-1"),
+ }
def test_remove(self, tmp_path):
s = self.gen_pkgset(tmp_path, "=dev-util/diffball-0.4\ndev-util/bsdiff")