MCPcopy Index your code
hub / github.com/python/cpython / test_key_attribute

Method test_key_attribute

Lib/test/test_zoneinfo/test_zoneinfo.py:199–222  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

197 self.assertRegex(repr(zi_ff_nk), class_name)
198
199 def test_key_attribute(self):
200 key = next(iter(self.zones()))
201
202 def from_file_nokey(key):
203 with open(self.zoneinfo_data.path_from_key(key), "rb") as f:
204 return self.klass.from_file(f)
205
206 constructors = (
207 ("Primary constructor", self.klass, key),
208 ("no_cache", self.klass.no_cache, key),
209 ("from_file", from_file_nokey, None),
210 )
211
212 for msg, constructor, expected in constructors:
213 zi = constructor(key)
214
215 # Ensure that the key attribute is set to the input to ``key``
216 with self.subTest(msg):
217 self.assertEqual(zi.key, expected)
218
219 # Ensure that the key attribute is read-only
220 with self.subTest(f"{msg}: readonly"):
221 with self.assertRaises(AttributeError):
222 zi.key = "Some/Value"
223
224 def test_bad_keys(self):
225 bad_keys = [

Callers

nothing calls this directly

Calls 5

zonesMethod · 0.95
constructorFunction · 0.85
subTestMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected