Gentoo Archives: gentoo-commits

From: Arthur Zamarin <arthurzam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/pkgcore/pkgcore:master commit in: tests/pkgsets/, tests/fs/, tests/ebuild/, src/pkgcore/pkgsets/
Date: Sat, 31 Dec 2022 21:07:53
Message-Id: 1672520850.d166566af2f2c84c061106986943c2cb872e7196.arthurzam@gentoo
1 commit: d166566af2f2c84c061106986943c2cb872e7196
2 Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
3 AuthorDate: Sat Dec 31 21:07:30 2022 +0000
4 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
5 CommitDate: Sat Dec 31 21:07:30 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=d166566a
7
8 properly close open file handlers during tests
9
10 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>
11
12 src/pkgcore/pkgsets/filelist.py | 6 +++---
13 tests/ebuild/test_domain.py | 8 ++++----
14 tests/ebuild/test_repo_objs.py | 8 +++-----
15 tests/fs/test_fs.py | 3 ++-
16 tests/fs/test_livefs.py | 3 ++-
17 tests/pkgsets/test_filelist.py | 17 ++++++-----------
18 6 files changed, 20 insertions(+), 25 deletions(-)
19
20 diff --git a/src/pkgcore/pkgsets/filelist.py b/src/pkgcore/pkgsets/filelist.py
21 index 8597d6962..d3f58b6ae 100644
22 --- a/src/pkgcore/pkgsets/filelist.py
23 +++ b/src/pkgcore/pkgsets/filelist.py
24 @@ -36,7 +36,7 @@ class FileList:
25 elif x.startswith("@"):
26 if self.error_on_subsets:
27 raise ValueError(
28 - "set %s isn't a valid atom in pkgset %r" % (x, self.path)
29 + f"set {x} isn't a valid atom in pkgset {self.path!r}"
30 )
31 logger.warning(
32 "set item %r found in pkgset %r: it will be "
33 @@ -47,8 +47,8 @@ class FileList:
34 )
35 continue
36 s.add(atom(x))
37 - except InvalidDependency as e:
38 - raise errors.ParsingError("parsing %r" % self.path, exception=e) from e
39 + except InvalidDependency as exc:
40 + raise errors.ParsingError(f"parsing {self.path!r}", exception=exc) from exc
41
42 return s
43
44
45 diff --git a/tests/ebuild/test_domain.py b/tests/ebuild/test_domain.py
46 index 90594b9d6..28706e254 100644
47 --- a/tests/ebuild/test_domain.py
48 +++ b/tests/ebuild/test_domain.py
49 @@ -37,8 +37,8 @@ class TestDomain:
50 # assert the base state; no files, no content.
51 assert () == self.mk_domain().pkg_use
52
53 - open(self.pusedir / "00", "w").write("*/* X")
54 - open(self.pusedir / "01", "w").write("*/* -X Y")
55 + (self.pusedir / "00").write_text("*/* X")
56 + (self.pusedir / "01").write_text("*/* -X Y")
57
58 # Force the returned ordering to be reversed; this is to assert that
59 # the domain forces a sort.
60 @@ -56,7 +56,7 @@ class TestDomain:
61 ) == self.mk_domain().pkg_use
62
63 def test_use_expand_syntax(self):
64 - open(self.pusedir / "a", "w").write(
65 + (self.pusedir / "a").write_text(
66 textwrap.dedent(
67 """
68 */* x_y1
69 @@ -81,7 +81,7 @@ class TestDomain:
70 ) == self.mk_domain().pkg_use
71
72 def test_use_flag_parsing_enforcement(self):
73 - open(self.pusedir / "a", "w").write("*/* X:")
74 + (self.pusedir / "a").write_text("*/* X:")
75 # TODO: need to catch the warning here, but I'm not sure how.
76 # Meanwhile, ensure that the failed token is ignored.
77 assert ((packages.AlwaysTrue, ((), ())),) == self.mk_domain().pkg_use
78
79 diff --git a/tests/ebuild/test_repo_objs.py b/tests/ebuild/test_repo_objs.py
80 index 3babe3a11..f86f8fe06 100644
81 --- a/tests/ebuild/test_repo_objs.py
82 +++ b/tests/ebuild/test_repo_objs.py
83 @@ -48,7 +48,7 @@ class TestMetadataXml:
84 ls = f"<longdescription>{longdescription}</longdescription>\n"
85 sa = "<stabilize-allarches/>" if stabilize_allarches else ""
86 s = f"""<?xml version="1.0" encoding="UTF-8"?>
87 -<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
88 +<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
89 <pkgmetadata>
90 {cs}{ms}{us}{ls}{sa}</pkgmetadata>"""
91 return repo_objs.MetadataXml(data_source(s.encode("utf-8")))
92 @@ -155,11 +155,9 @@ Blake-light tragedy among the scholars of war.
93
94 def test_stabilize_allarches(self):
95 # missing
96 - assert False == self.get_metadata_xml().stabilize_allarches
97 + assert not self.get_metadata_xml().stabilize_allarches
98 # present
99 - assert (
100 - True == self.get_metadata_xml(stabilize_allarches=True).stabilize_allarches
101 - )
102 + assert self.get_metadata_xml(stabilize_allarches=True).stabilize_allarches
103
104
105 class TestProjectsXml:
106
107 diff --git a/tests/fs/test_fs.py b/tests/fs/test_fs.py
108 index d29b58c11..605be48ff 100644
109 --- a/tests/fs/test_fs.py
110 +++ b/tests/fs/test_fs.py
111 @@ -106,7 +106,8 @@ class Test_fsFile(base):
112 o = self.make_obj(__file__)
113 with open(__file__) as f:
114 raw_data = f.read()
115 - assert o.data.text_fileobj().read() == raw_data
116 + with o.data.text_fileobj() as f:
117 + assert f.read() == raw_data
118
119 o = self.make_obj(
120 "/bin/this-file-should-not-exist-nor-be-read", data=data_source(raw_data)
121
122 diff --git a/tests/fs/test_livefs.py b/tests/fs/test_livefs.py
123 index f6fe28d0c..3dbad6125 100644
124 --- a/tests/fs/test_livefs.py
125 +++ b/tests/fs/test_livefs.py
126 @@ -29,7 +29,8 @@ class TestFsObjs:
127 assert o.location, "/tmp/etc/passwd"
128 assert o.data.path, "/etc/passwd"
129 with open("/etc/passwd", "rb") as f:
130 - assert o.data.bytes_fileobj().read(), f.read()
131 + with o.data.bytes_fileobj() as fileobj:
132 + assert fileobj.read() == f.read()
133
134 def test_gen_obj_reg(self, tmp_path):
135 (path := tmp_path / "reg_obj").touch()
136
137 diff --git a/tests/pkgsets/test_filelist.py b/tests/pkgsets/test_filelist.py
138 index 5f34e1398..74158c2e4 100644
139 --- a/tests/pkgsets/test_filelist.py
140 +++ b/tests/pkgsets/test_filelist.py
141 @@ -47,17 +47,12 @@ class TestFileList:
142
143 assert {
144 atom(line) for line in (tmp_path / "file").read_text().splitlines()
145 - } == set(
146 - map(
147 - atom,
148 - (
149 - "dev-util/diffball",
150 - "=dev-util/bsdiff-0.4",
151 - "dev-util/foon",
152 - "=dev-util/lib-1",
153 - ),
154 - )
155 - )
156 + } == {
157 + atom("dev-util/diffball"),
158 + atom("=dev-util/bsdiff-0.4"),
159 + atom("dev-util/foon"),
160 + atom("=dev-util/lib-1"),
161 + }
162
163 def test_remove(self, tmp_path):
164 s = self.gen_pkgset(tmp_path, "=dev-util/diffball-0.4\ndev-util/bsdiff")