mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-07-28 08:58:29 -06:00
Removed the Requirement to Install Python and NodeJS (Now Bundled with Borealis)
This commit is contained in:
5
Dependencies/Python/Lib/test/test_zoneinfo/__init__.py
vendored
Normal file
5
Dependencies/Python/Lib/test/test_zoneinfo/__init__.py
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import os
|
||||
from test.support import load_package_tests
|
||||
|
||||
def load_tests(*args):
|
||||
return load_package_tests(os.path.dirname(__file__), *args)
|
3
Dependencies/Python/Lib/test/test_zoneinfo/__main__.py
vendored
Normal file
3
Dependencies/Python/Lib/test/test_zoneinfo/__main__.py
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import unittest
|
||||
|
||||
unittest.main('test.test_zoneinfo')
|
100
Dependencies/Python/Lib/test/test_zoneinfo/_support.py
vendored
Normal file
100
Dependencies/Python/Lib/test/test_zoneinfo/_support.py
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
import contextlib
|
||||
import functools
|
||||
import sys
|
||||
import threading
|
||||
import unittest
|
||||
from test.support.import_helper import import_fresh_module
|
||||
|
||||
OS_ENV_LOCK = threading.Lock()
|
||||
TZPATH_LOCK = threading.Lock()
|
||||
TZPATH_TEST_LOCK = threading.Lock()
|
||||
|
||||
|
||||
def call_once(f):
|
||||
"""Decorator that ensures a function is only ever called once."""
|
||||
lock = threading.Lock()
|
||||
cached = functools.lru_cache(None)(f)
|
||||
|
||||
@functools.wraps(f)
|
||||
def inner():
|
||||
with lock:
|
||||
return cached()
|
||||
|
||||
return inner
|
||||
|
||||
|
||||
@call_once
|
||||
def get_modules():
|
||||
"""Retrieve two copies of zoneinfo: pure Python and C accelerated.
|
||||
|
||||
Because this function manipulates the import system in a way that might
|
||||
be fragile or do unexpected things if it is run many times, it uses a
|
||||
`call_once` decorator to ensure that this is only ever called exactly
|
||||
one time — in other words, when using this function you will only ever
|
||||
get one copy of each module rather than a fresh import each time.
|
||||
"""
|
||||
import zoneinfo as c_module
|
||||
|
||||
py_module = import_fresh_module("zoneinfo", blocked=["_zoneinfo"])
|
||||
|
||||
return py_module, c_module
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def set_zoneinfo_module(module):
|
||||
"""Make sure sys.modules["zoneinfo"] refers to `module`.
|
||||
|
||||
This is necessary because `pickle` will refuse to serialize
|
||||
an type calling itself `zoneinfo.ZoneInfo` unless `zoneinfo.ZoneInfo`
|
||||
refers to the same object.
|
||||
"""
|
||||
|
||||
NOT_PRESENT = object()
|
||||
old_zoneinfo = sys.modules.get("zoneinfo", NOT_PRESENT)
|
||||
sys.modules["zoneinfo"] = module
|
||||
yield
|
||||
if old_zoneinfo is not NOT_PRESENT:
|
||||
sys.modules["zoneinfo"] = old_zoneinfo
|
||||
else: # pragma: nocover
|
||||
sys.modules.pop("zoneinfo")
|
||||
|
||||
|
||||
class ZoneInfoTestBase(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.klass = cls.module.ZoneInfo
|
||||
super().setUpClass()
|
||||
|
||||
@contextlib.contextmanager
|
||||
def tzpath_context(self, tzpath, block_tzdata=True, lock=TZPATH_LOCK):
|
||||
def pop_tzdata_modules():
|
||||
tzdata_modules = {}
|
||||
for modname in list(sys.modules):
|
||||
if modname.split(".", 1)[0] != "tzdata": # pragma: nocover
|
||||
continue
|
||||
|
||||
tzdata_modules[modname] = sys.modules.pop(modname)
|
||||
|
||||
return tzdata_modules
|
||||
|
||||
with lock:
|
||||
if block_tzdata:
|
||||
# In order to fully exclude tzdata from the path, we need to
|
||||
# clear the sys.modules cache of all its contents — setting the
|
||||
# root package to None is not enough to block direct access of
|
||||
# already-imported submodules (though it will prevent new
|
||||
# imports of submodules).
|
||||
tzdata_modules = pop_tzdata_modules()
|
||||
sys.modules["tzdata"] = None
|
||||
|
||||
old_path = self.module.TZPATH
|
||||
try:
|
||||
self.module.reset_tzpath(tzpath)
|
||||
yield
|
||||
finally:
|
||||
if block_tzdata:
|
||||
sys.modules.pop("tzdata")
|
||||
for modname, module in tzdata_modules.items():
|
||||
sys.modules[modname] = module
|
||||
|
||||
self.module.reset_tzpath(old_path)
|
122
Dependencies/Python/Lib/test/test_zoneinfo/data/update_test_data.py
vendored
Normal file
122
Dependencies/Python/Lib/test/test_zoneinfo/data/update_test_data.py
vendored
Normal file
@ -0,0 +1,122 @@
|
||||
"""
|
||||
Script to automatically generate a JSON file containing time zone information.
|
||||
|
||||
This is done to allow "pinning" a small subset of the tzdata in the tests,
|
||||
since we are testing properties of a file that may be subject to change. For
|
||||
example, the behavior in the far future of any given zone is likely to change,
|
||||
but "does this give the right answer for this file in 2040" is still an
|
||||
important property to test.
|
||||
|
||||
This must be run from a computer with zoneinfo data installed.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import functools
|
||||
import json
|
||||
import lzma
|
||||
import pathlib
|
||||
import textwrap
|
||||
import typing
|
||||
|
||||
import zoneinfo
|
||||
|
||||
KEYS = [
|
||||
"Africa/Abidjan",
|
||||
"Africa/Casablanca",
|
||||
"America/Los_Angeles",
|
||||
"America/Santiago",
|
||||
"Asia/Tokyo",
|
||||
"Australia/Sydney",
|
||||
"Europe/Dublin",
|
||||
"Europe/Lisbon",
|
||||
"Europe/London",
|
||||
"Pacific/Kiritimati",
|
||||
"UTC",
|
||||
]
|
||||
|
||||
TEST_DATA_LOC = pathlib.Path(__file__).parent
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=None)
|
||||
def get_zoneinfo_path() -> pathlib.Path:
|
||||
"""Get the first zoneinfo directory on TZPATH containing the "UTC" zone."""
|
||||
key = "UTC"
|
||||
for path in map(pathlib.Path, zoneinfo.TZPATH):
|
||||
if (path / key).exists():
|
||||
return path
|
||||
else:
|
||||
raise OSError("Cannot find time zone data.")
|
||||
|
||||
|
||||
def get_zoneinfo_metadata() -> typing.Dict[str, str]:
|
||||
path = get_zoneinfo_path()
|
||||
|
||||
tzdata_zi = path / "tzdata.zi"
|
||||
if not tzdata_zi.exists():
|
||||
# tzdata.zi is necessary to get the version information
|
||||
raise OSError("Time zone data does not include tzdata.zi.")
|
||||
|
||||
with open(tzdata_zi, "r") as f:
|
||||
version_line = next(f)
|
||||
|
||||
_, version = version_line.strip().rsplit(" ", 1)
|
||||
|
||||
if (
|
||||
not version[0:4].isdigit()
|
||||
or len(version) < 5
|
||||
or not version[4:].isalpha()
|
||||
):
|
||||
raise ValueError(
|
||||
"Version string should be YYYYx, "
|
||||
+ "where YYYY is the year and x is a letter; "
|
||||
+ f"found: {version}"
|
||||
)
|
||||
|
||||
return {"version": version}
|
||||
|
||||
|
||||
def get_zoneinfo(key: str) -> bytes:
|
||||
path = get_zoneinfo_path()
|
||||
|
||||
with open(path / key, "rb") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def encode_compressed(data: bytes) -> typing.List[str]:
|
||||
compressed_zone = lzma.compress(data)
|
||||
raw = base64.b85encode(compressed_zone)
|
||||
|
||||
raw_data_str = raw.decode("utf-8")
|
||||
|
||||
data_str = textwrap.wrap(raw_data_str, width=70)
|
||||
return data_str
|
||||
|
||||
|
||||
def load_compressed_keys() -> typing.Dict[str, typing.List[str]]:
|
||||
output = {key: encode_compressed(get_zoneinfo(key)) for key in KEYS}
|
||||
|
||||
return output
|
||||
|
||||
|
||||
def update_test_data(fname: str = "zoneinfo_data.json") -> None:
|
||||
TEST_DATA_LOC.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
# Annotation required: https://github.com/python/mypy/issues/8772
|
||||
json_kwargs: typing.Dict[str, typing.Any] = dict(
|
||||
indent=2, sort_keys=True,
|
||||
)
|
||||
|
||||
compressed_keys = load_compressed_keys()
|
||||
metadata = get_zoneinfo_metadata()
|
||||
output = {
|
||||
"metadata": metadata,
|
||||
"data": compressed_keys,
|
||||
}
|
||||
|
||||
with open(TEST_DATA_LOC / fname, "w") as f:
|
||||
json.dump(output, f, **json_kwargs)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
update_test_data()
|
190
Dependencies/Python/Lib/test/test_zoneinfo/data/zoneinfo_data.json
vendored
Normal file
190
Dependencies/Python/Lib/test/test_zoneinfo/data/zoneinfo_data.json
vendored
Normal file
@ -0,0 +1,190 @@
|
||||
{
|
||||
"data": {
|
||||
"Africa/Abidjan": [
|
||||
"{Wp48S^xk9=GL@E0stWa761SMbT8$j-~f{VGF<>F7KxBg5R*{Ksocg8-YYVul=v7vZzaHN",
|
||||
"uC=da5UI2rH18c!OnjV{y4u(+A!!VBKmY&$ORw>7UO^(500B;v0RR91bXh%WvBYQl0ssI2",
|
||||
"00dcD"
|
||||
],
|
||||
"Africa/Casablanca": [
|
||||
"{Wp48S^xk9=GL@E0stWa761SMbT8$j;0b&Kz+C_;7KxBg5R*{N&yjMUR~;C-fDaSOU;q-~",
|
||||
"FqW+4{YBjbcw}`a!dW>b)R2-0a+uwf`P3{_Y@HuCz}S$J$ZJ>R_V<~|Fk>sgX4=%0vUrh-",
|
||||
"lt@YP^Wrus;j?`Th#xRPzf<<~Hp4DH^gZX>d{+WOp~HNu8!{uWu}&XphAd{j1;rB4|9?R!",
|
||||
"pqruAFUMt8#*WcrVS{;kLlY(cJRV$w?d2car%R<ALOSO?^`4;ZZtI)%f^^G^>s>q9BgTU4",
|
||||
"Ht-tQKZ7Z`9QqOb?R#b%z?rk>!CkH7jy3wja4NG2q)H}fNRKg8v{);Em;K3Cncf4C6&Oaj",
|
||||
"V+DbX%o4+)CV3+e!Lm6dutu(0BQpH1T?W(~cQtKV*^_Pdx!LirjpTs?Bmt@vktjLq4;)O!",
|
||||
"rrly=c*rwTwMJFd0I57`hgkc?=nyI4RZf9W$6DCWugmf&)wk^tWH17owj=#PGH7Xv-?9$j",
|
||||
"njwDlkOE+BFNR9YXEmBpO;rqEw=e2IR-8^(W;8ma?M3JVd($2T>IW+0tk|Gm8>ftukRQ9J",
|
||||
"8k3brzqMnVyjsLI-CKneFa)Lxvp_a<CkQEd#(pMA^rr}rBNElGA=*!M)puBdoErR9{kWL@",
|
||||
"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||
"{Wp48S^xk9=GL@E0stWa761SMbT8$j-~e#|9bEt_7KxBg5R*|3h1|xhHLji!C57qW6L*|H",
|
||||
"pEErm00000ygu;I+>V)?00B92fhY-(AGY&-0RR9100dcD"
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"version": "2020a"
|
||||
}
|
||||
}
|
2260
Dependencies/Python/Lib/test/test_zoneinfo/test_zoneinfo.py
vendored
Normal file
2260
Dependencies/Python/Lib/test/test_zoneinfo/test_zoneinfo.py
vendored
Normal file
File diff suppressed because it is too large
Load Diff
368
Dependencies/Python/Lib/test/test_zoneinfo/test_zoneinfo_property.py
vendored
Normal file
368
Dependencies/Python/Lib/test/test_zoneinfo/test_zoneinfo_property.py
vendored
Normal file
@ -0,0 +1,368 @@
|
||||
import contextlib
|
||||
import datetime
|
||||
import os
|
||||
import pickle
|
||||
import unittest
|
||||
import zoneinfo
|
||||
|
||||
from test.support.hypothesis_helper import hypothesis
|
||||
|
||||
import test.test_zoneinfo._support as test_support
|
||||
|
||||
ZoneInfoTestBase = test_support.ZoneInfoTestBase
|
||||
|
||||
py_zoneinfo, c_zoneinfo = test_support.get_modules()
|
||||
|
||||
UTC = datetime.timezone.utc
|
||||
MIN_UTC = datetime.datetime.min.replace(tzinfo=UTC)
|
||||
MAX_UTC = datetime.datetime.max.replace(tzinfo=UTC)
|
||||
ZERO = datetime.timedelta(0)
|
||||
|
||||
|
||||
def _valid_keys():
|
||||
"""Get available time zones, including posix/ and right/ directories."""
|
||||
from importlib import resources
|
||||
|
||||
available_zones = sorted(zoneinfo.available_timezones())
|
||||
TZPATH = zoneinfo.TZPATH
|
||||
|
||||
def valid_key(key):
|
||||
for root in TZPATH:
|
||||
key_file = os.path.join(root, key)
|
||||
if os.path.exists(key_file):
|
||||
return True
|
||||
|
||||
components = key.split("/")
|
||||
package_name = ".".join(["tzdata.zoneinfo"] + components[:-1])
|
||||
resource_name = components[-1]
|
||||
|
||||
try:
|
||||
return resources.files(package_name).joinpath(resource_name).is_file()
|
||||
except ModuleNotFoundError:
|
||||
return False
|
||||
|
||||
# This relies on the fact that dictionaries maintain insertion order — for
|
||||
# shrinking purposes, it is preferable to start with the standard version,
|
||||
# then move to the posix/ version, then to the right/ version.
|
||||
out_zones = {"": available_zones}
|
||||
for prefix in ["posix", "right"]:
|
||||
prefix_out = []
|
||||
for key in available_zones:
|
||||
prefix_key = f"{prefix}/{key}"
|
||||
if valid_key(prefix_key):
|
||||
prefix_out.append(prefix_key)
|
||||
|
||||
out_zones[prefix] = prefix_out
|
||||
|
||||
output = []
|
||||
for keys in out_zones.values():
|
||||
output.extend(keys)
|
||||
|
||||
return output
|
||||
|
||||
|
||||
VALID_KEYS = _valid_keys()
|
||||
if not VALID_KEYS:
|
||||
raise unittest.SkipTest("No time zone data available")
|
||||
|
||||
|
||||
def valid_keys():
|
||||
return hypothesis.strategies.sampled_from(VALID_KEYS)
|
||||
|
||||
|
||||
KEY_EXAMPLES = [
|
||||
"Africa/Abidjan",
|
||||
"Africa/Casablanca",
|
||||
"America/Los_Angeles",
|
||||
"America/Santiago",
|
||||
"Asia/Tokyo",
|
||||
"Australia/Sydney",
|
||||
"Europe/Dublin",
|
||||
"Europe/Lisbon",
|
||||
"Europe/London",
|
||||
"Pacific/Kiritimati",
|
||||
"UTC",
|
||||
]
|
||||
|
||||
|
||||
def add_key_examples(f):
|
||||
for key in KEY_EXAMPLES:
|
||||
f = hypothesis.example(key)(f)
|
||||
return f
|
||||
|
||||
|
||||
class ZoneInfoTest(ZoneInfoTestBase):
|
||||
module = py_zoneinfo
|
||||
|
||||
@hypothesis.given(key=valid_keys())
|
||||
@add_key_examples
|
||||
def test_str(self, key):
|
||||
zi = self.klass(key)
|
||||
self.assertEqual(str(zi), key)
|
||||
|
||||
@hypothesis.given(key=valid_keys())
|
||||
@add_key_examples
|
||||
def test_key(self, key):
|
||||
zi = self.klass(key)
|
||||
|
||||
self.assertEqual(zi.key, key)
|
||||
|
||||
@hypothesis.given(
|
||||
dt=hypothesis.strategies.one_of(
|
||||
hypothesis.strategies.datetimes(), hypothesis.strategies.times()
|
||||
)
|
||||
)
|
||||
@hypothesis.example(dt=datetime.datetime.min)
|
||||
@hypothesis.example(dt=datetime.datetime.max)
|
||||
@hypothesis.example(dt=datetime.datetime(1970, 1, 1))
|
||||
@hypothesis.example(dt=datetime.datetime(2039, 1, 1))
|
||||
@hypothesis.example(dt=datetime.time(0))
|
||||
@hypothesis.example(dt=datetime.time(12, 0))
|
||||
@hypothesis.example(dt=datetime.time(23, 59, 59, 999999))
|
||||
def test_utc(self, dt):
|
||||
zi = self.klass("UTC")
|
||||
dt_zi = dt.replace(tzinfo=zi)
|
||||
|
||||
self.assertEqual(dt_zi.utcoffset(), ZERO)
|
||||
self.assertEqual(dt_zi.dst(), ZERO)
|
||||
self.assertEqual(dt_zi.tzname(), "UTC")
|
||||
|
||||
|
||||
class CZoneInfoTest(ZoneInfoTest):
|
||||
module = c_zoneinfo
|
||||
|
||||
|
||||
class ZoneInfoPickleTest(ZoneInfoTestBase):
|
||||
module = py_zoneinfo
|
||||
|
||||
def setUp(self):
|
||||
with contextlib.ExitStack() as stack:
|
||||
stack.enter_context(test_support.set_zoneinfo_module(self.module))
|
||||
self.addCleanup(stack.pop_all().close)
|
||||
|
||||
super().setUp()
|
||||
|
||||
@hypothesis.given(key=valid_keys())
|
||||
@add_key_examples
|
||||
def test_pickle_unpickle_cache(self, key):
|
||||
zi = self.klass(key)
|
||||
pkl_str = pickle.dumps(zi)
|
||||
zi_rt = pickle.loads(pkl_str)
|
||||
|
||||
self.assertIs(zi, zi_rt)
|
||||
|
||||
@hypothesis.given(key=valid_keys())
|
||||
@add_key_examples
|
||||
def test_pickle_unpickle_no_cache(self, key):
|
||||
zi = self.klass.no_cache(key)
|
||||
pkl_str = pickle.dumps(zi)
|
||||
zi_rt = pickle.loads(pkl_str)
|
||||
|
||||
self.assertIsNot(zi, zi_rt)
|
||||
self.assertEqual(str(zi), str(zi_rt))
|
||||
|
||||
@hypothesis.given(key=valid_keys())
|
||||
@add_key_examples
|
||||
def test_pickle_unpickle_cache_multiple_rounds(self, key):
|
||||
"""Test that pickle/unpickle is idempotent."""
|
||||
zi_0 = self.klass(key)
|
||||
pkl_str_0 = pickle.dumps(zi_0)
|
||||
zi_1 = pickle.loads(pkl_str_0)
|
||||
pkl_str_1 = pickle.dumps(zi_1)
|
||||
zi_2 = pickle.loads(pkl_str_1)
|
||||
pkl_str_2 = pickle.dumps(zi_2)
|
||||
|
||||
self.assertEqual(pkl_str_0, pkl_str_1)
|
||||
self.assertEqual(pkl_str_1, pkl_str_2)
|
||||
|
||||
self.assertIs(zi_0, zi_1)
|
||||
self.assertIs(zi_0, zi_2)
|
||||
self.assertIs(zi_1, zi_2)
|
||||
|
||||
@hypothesis.given(key=valid_keys())
|
||||
@add_key_examples
|
||||
def test_pickle_unpickle_no_cache_multiple_rounds(self, key):
|
||||
"""Test that pickle/unpickle is idempotent."""
|
||||
zi_cache = self.klass(key)
|
||||
|
||||
zi_0 = self.klass.no_cache(key)
|
||||
pkl_str_0 = pickle.dumps(zi_0)
|
||||
zi_1 = pickle.loads(pkl_str_0)
|
||||
pkl_str_1 = pickle.dumps(zi_1)
|
||||
zi_2 = pickle.loads(pkl_str_1)
|
||||
pkl_str_2 = pickle.dumps(zi_2)
|
||||
|
||||
self.assertEqual(pkl_str_0, pkl_str_1)
|
||||
self.assertEqual(pkl_str_1, pkl_str_2)
|
||||
|
||||
self.assertIsNot(zi_0, zi_1)
|
||||
self.assertIsNot(zi_0, zi_2)
|
||||
self.assertIsNot(zi_1, zi_2)
|
||||
|
||||
self.assertIsNot(zi_0, zi_cache)
|
||||
self.assertIsNot(zi_1, zi_cache)
|
||||
self.assertIsNot(zi_2, zi_cache)
|
||||
|
||||
|
||||
class CZoneInfoPickleTest(ZoneInfoPickleTest):
|
||||
module = c_zoneinfo
|
||||
|
||||
|
||||
class ZoneInfoCacheTest(ZoneInfoTestBase):
|
||||
module = py_zoneinfo
|
||||
|
||||
@hypothesis.given(key=valid_keys())
|
||||
@add_key_examples
|
||||
def test_cache(self, key):
|
||||
zi_0 = self.klass(key)
|
||||
zi_1 = self.klass(key)
|
||||
|
||||
self.assertIs(zi_0, zi_1)
|
||||
|
||||
@hypothesis.given(key=valid_keys())
|
||||
@add_key_examples
|
||||
def test_no_cache(self, key):
|
||||
zi_0 = self.klass.no_cache(key)
|
||||
zi_1 = self.klass.no_cache(key)
|
||||
|
||||
self.assertIsNot(zi_0, zi_1)
|
||||
|
||||
|
||||
class CZoneInfoCacheTest(ZoneInfoCacheTest):
|
||||
klass = c_zoneinfo.ZoneInfo
|
||||
|
||||
|
||||
class PythonCConsistencyTest(unittest.TestCase):
|
||||
"""Tests that the C and Python versions do the same thing."""
|
||||
|
||||
def _is_ambiguous(self, dt):
|
||||
return dt.replace(fold=not dt.fold).utcoffset() == dt.utcoffset()
|
||||
|
||||
@hypothesis.given(dt=hypothesis.strategies.datetimes(), key=valid_keys())
|
||||
@hypothesis.example(dt=datetime.datetime.min, key="America/New_York")
|
||||
@hypothesis.example(dt=datetime.datetime.max, key="America/New_York")
|
||||
@hypothesis.example(dt=datetime.datetime(1970, 1, 1), key="America/New_York")
|
||||
@hypothesis.example(dt=datetime.datetime(2020, 1, 1), key="Europe/Paris")
|
||||
@hypothesis.example(dt=datetime.datetime(2020, 6, 1), key="Europe/Paris")
|
||||
def test_same_str(self, dt, key):
|
||||
py_dt = dt.replace(tzinfo=py_zoneinfo.ZoneInfo(key))
|
||||
c_dt = dt.replace(tzinfo=c_zoneinfo.ZoneInfo(key))
|
||||
|
||||
self.assertEqual(str(py_dt), str(c_dt))
|
||||
|
||||
@hypothesis.given(dt=hypothesis.strategies.datetimes(), key=valid_keys())
|
||||
@hypothesis.example(dt=datetime.datetime(1970, 1, 1), key="America/New_York")
|
||||
@hypothesis.example(dt=datetime.datetime(2020, 2, 5), key="America/New_York")
|
||||
@hypothesis.example(dt=datetime.datetime(2020, 8, 12), key="America/New_York")
|
||||
@hypothesis.example(dt=datetime.datetime(2040, 1, 1), key="Africa/Casablanca")
|
||||
@hypothesis.example(dt=datetime.datetime(1970, 1, 1), key="Europe/Paris")
|
||||
@hypothesis.example(dt=datetime.datetime(2040, 1, 1), key="Europe/Paris")
|
||||
@hypothesis.example(dt=datetime.datetime.min, key="Asia/Tokyo")
|
||||
@hypothesis.example(dt=datetime.datetime.max, key="Asia/Tokyo")
|
||||
def test_same_offsets_and_names(self, dt, key):
|
||||
py_dt = dt.replace(tzinfo=py_zoneinfo.ZoneInfo(key))
|
||||
c_dt = dt.replace(tzinfo=c_zoneinfo.ZoneInfo(key))
|
||||
|
||||
self.assertEqual(py_dt.tzname(), c_dt.tzname())
|
||||
self.assertEqual(py_dt.utcoffset(), c_dt.utcoffset())
|
||||
self.assertEqual(py_dt.dst(), c_dt.dst())
|
||||
|
||||
@hypothesis.given(
|
||||
dt=hypothesis.strategies.datetimes(timezones=hypothesis.strategies.just(UTC)),
|
||||
key=valid_keys(),
|
||||
)
|
||||
@hypothesis.example(dt=MIN_UTC, key="Asia/Tokyo")
|
||||
@hypothesis.example(dt=MAX_UTC, key="Asia/Tokyo")
|
||||
@hypothesis.example(dt=MIN_UTC, key="America/New_York")
|
||||
@hypothesis.example(dt=MAX_UTC, key="America/New_York")
|
||||
@hypothesis.example(
|
||||
dt=datetime.datetime(2006, 10, 29, 5, 15, tzinfo=UTC),
|
||||
key="America/New_York",
|
||||
)
|
||||
def test_same_from_utc(self, dt, key):
|
||||
py_zi = py_zoneinfo.ZoneInfo(key)
|
||||
c_zi = c_zoneinfo.ZoneInfo(key)
|
||||
|
||||
# Convert to UTC: This can overflow, but we just care about consistency
|
||||
py_overflow_exc = None
|
||||
c_overflow_exc = None
|
||||
try:
|
||||
py_dt = dt.astimezone(py_zi)
|
||||
except OverflowError as e:
|
||||
py_overflow_exc = e
|
||||
|
||||
try:
|
||||
c_dt = dt.astimezone(c_zi)
|
||||
except OverflowError as e:
|
||||
c_overflow_exc = e
|
||||
|
||||
if (py_overflow_exc is not None) != (c_overflow_exc is not None):
|
||||
raise py_overflow_exc or c_overflow_exc # pragma: nocover
|
||||
|
||||
if py_overflow_exc is not None:
|
||||
return # Consistently raises the same exception
|
||||
|
||||
# PEP 495 says that an inter-zone comparison between ambiguous
|
||||
# datetimes is always False.
|
||||
if py_dt != c_dt:
|
||||
self.assertEqual(
|
||||
self._is_ambiguous(py_dt),
|
||||
self._is_ambiguous(c_dt),
|
||||
(py_dt, c_dt),
|
||||
)
|
||||
|
||||
self.assertEqual(py_dt.tzname(), c_dt.tzname())
|
||||
self.assertEqual(py_dt.utcoffset(), c_dt.utcoffset())
|
||||
self.assertEqual(py_dt.dst(), c_dt.dst())
|
||||
|
||||
@hypothesis.given(dt=hypothesis.strategies.datetimes(), key=valid_keys())
|
||||
@hypothesis.example(dt=datetime.datetime.max, key="America/New_York")
|
||||
@hypothesis.example(dt=datetime.datetime.min, key="America/New_York")
|
||||
@hypothesis.example(dt=datetime.datetime.min, key="Asia/Tokyo")
|
||||
@hypothesis.example(dt=datetime.datetime.max, key="Asia/Tokyo")
|
||||
def test_same_to_utc(self, dt, key):
|
||||
py_dt = dt.replace(tzinfo=py_zoneinfo.ZoneInfo(key))
|
||||
c_dt = dt.replace(tzinfo=c_zoneinfo.ZoneInfo(key))
|
||||
|
||||
# Convert from UTC: Overflow OK if it happens in both implementations
|
||||
py_overflow_exc = None
|
||||
c_overflow_exc = None
|
||||
try:
|
||||
py_utc = py_dt.astimezone(UTC)
|
||||
except OverflowError as e:
|
||||
py_overflow_exc = e
|
||||
|
||||
try:
|
||||
c_utc = c_dt.astimezone(UTC)
|
||||
except OverflowError as e:
|
||||
c_overflow_exc = e
|
||||
|
||||
if (py_overflow_exc is not None) != (c_overflow_exc is not None):
|
||||
raise py_overflow_exc or c_overflow_exc # pragma: nocover
|
||||
|
||||
if py_overflow_exc is not None:
|
||||
return # Consistently raises the same exception
|
||||
|
||||
self.assertEqual(py_utc, c_utc)
|
||||
|
||||
@hypothesis.given(key=valid_keys())
|
||||
@add_key_examples
|
||||
def test_cross_module_pickle(self, key):
|
||||
py_zi = py_zoneinfo.ZoneInfo(key)
|
||||
c_zi = c_zoneinfo.ZoneInfo(key)
|
||||
|
||||
with test_support.set_zoneinfo_module(py_zoneinfo):
|
||||
py_pkl = pickle.dumps(py_zi)
|
||||
|
||||
with test_support.set_zoneinfo_module(c_zoneinfo):
|
||||
c_pkl = pickle.dumps(c_zi)
|
||||
|
||||
with test_support.set_zoneinfo_module(c_zoneinfo):
|
||||
# Python → C
|
||||
py_to_c_zi = pickle.loads(py_pkl)
|
||||
self.assertIs(py_to_c_zi, c_zi)
|
||||
|
||||
with test_support.set_zoneinfo_module(py_zoneinfo):
|
||||
# C → Python
|
||||
c_to_py_zi = pickle.loads(c_pkl)
|
||||
self.assertIs(c_to_py_zi, py_zi)
|
Reference in New Issue
Block a user