* [gentoo-commits] proj/pkgcore/pkgcore:master commit in: tests/pkgsets/, tests/fs/, tests/ebuild/, src/pkgcore/pkgsets/
@ 2022-12-31 21:07 Arthur Zamarin
0 siblings, 0 replies; only message in thread
From: Arthur Zamarin @ 2022-12-31 21:07 UTC (permalink / raw
To: gentoo-commits
commit: d166566af2f2c84c061106986943c2cb872e7196
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 31 21:07:30 2022 +0000
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sat Dec 31 21:07:30 2022 +0000
URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=d166566a
properly close open file handlers during tests
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>
src/pkgcore/pkgsets/filelist.py | 6 +++---
tests/ebuild/test_domain.py | 8 ++++----
tests/ebuild/test_repo_objs.py | 8 +++-----
tests/fs/test_fs.py | 3 ++-
tests/fs/test_livefs.py | 3 ++-
tests/pkgsets/test_filelist.py | 17 ++++++-----------
6 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/src/pkgcore/pkgsets/filelist.py b/src/pkgcore/pkgsets/filelist.py
index 8597d6962..d3f58b6ae 100644
--- a/src/pkgcore/pkgsets/filelist.py
+++ b/src/pkgcore/pkgsets/filelist.py
@@ -36,7 +36,7 @@ class FileList:
elif x.startswith("@"):
if self.error_on_subsets:
raise ValueError(
- "set %s isn't a valid atom in pkgset %r" % (x, self.path)
+ f"set {x} isn't a valid atom in pkgset {self.path!r}"
)
logger.warning(
"set item %r found in pkgset %r: it will be "
@@ -47,8 +47,8 @@ class FileList:
)
continue
s.add(atom(x))
- except InvalidDependency as e:
- raise errors.ParsingError("parsing %r" % self.path, exception=e) from e
+ except InvalidDependency as exc:
+ raise errors.ParsingError(f"parsing {self.path!r}", exception=exc) from exc
return s
diff --git a/tests/ebuild/test_domain.py b/tests/ebuild/test_domain.py
index 90594b9d6..28706e254 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 3babe3a11..f86f8fe06 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 d29b58c11..605be48ff 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 f6fe28d0c..3dbad6125 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 5f34e1398..74158c2e4 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")
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-12-31 21:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-31 21:07 [gentoo-commits] proj/pkgcore/pkgcore:master commit in: tests/pkgsets/, tests/fs/, tests/ebuild/, src/pkgcore/pkgsets/ Arthur Zamarin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox