From 1b19b66e2634deb04217fd9a8d99a3fc668b9bee Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Fri, 13 Apr 2018 16:08:41 +0800 Subject: [PATCH 1/3] Purge strict-rfc3339 and timestamp from prettytoml And replace the date/time dumping with built-in datetime operations. --- pipenv/patched/prettytoml/tokens/py2toml.py | 9 +- pipenv/vendor/strict_rfc3339.py | 202 -------------------- pipenv/vendor/timestamp.py | 9 - 3 files changed, 4 insertions(+), 216 deletions(-) delete mode 100644 pipenv/vendor/strict_rfc3339.py delete mode 100644 pipenv/vendor/timestamp.py diff --git a/pipenv/patched/prettytoml/tokens/py2toml.py b/pipenv/patched/prettytoml/tokens/py2toml.py index 4043601d..82991958 100755 --- a/pipenv/patched/prettytoml/tokens/py2toml.py +++ b/pipenv/patched/prettytoml/tokens/py2toml.py @@ -5,11 +5,8 @@ A converter of python values to TOML Token instances. import codecs import datetime import six -import strict_rfc3339 -import timestamp from prettytoml import tokens import re -from prettytoml.elements.metadata import NewlineElement from prettytoml.errors import TOMLError from prettytoml.tokens import Token from prettytoml.util import chunkate_string @@ -49,8 +46,10 @@ def create_primitive_token(value, multiline_strings_allowed=True): elif isinstance(value, float): return tokens.Token(tokens.TYPE_FLOAT, u'{}'.format(value)) elif isinstance(value, (datetime.datetime, datetime.date, datetime.time)): - ts = timestamp(value) // 1000 - return tokens.Token(tokens.TYPE_DATE, strict_rfc3339.timestamp_to_rfc3339_utcoffset(ts)) + s = value.isoformat() + if s.endswith('+00:00'): + s = s[:-6] + 'Z' + return tokens.Token(tokens.TYPE_DATE, s) elif isinstance(value, six.string_types): return create_string_token(value, multiline_strings_allowed=multiline_strings_allowed) diff --git a/pipenv/vendor/strict_rfc3339.py b/pipenv/vendor/strict_rfc3339.py deleted file mode 100644 index 4558c01b..00000000 --- a/pipenv/vendor/strict_rfc3339.py +++ /dev/null @@ -1,202 +0,0 @@ -# Copyright 2012 (C) Daniel Richman, Adam Greig -# -# This file is part of strict_rfc3339. -# -# strict_rfc3339 is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# strict_rfc3339 is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with strict_rfc3339. If not, see . - -""" -Super simple lightweight RFC3339 functions -""" - -import re -import time -import calendar - -__all__ = ["validate_rfc3339", - "InvalidRFC3339Error", - "rfc3339_to_timestamp", - "timestamp_to_rfc3339_utcoffset", - "timestamp_to_rfc3339_localoffset", - "now_to_rfc3339_utcoffset", - "now_to_rfc3339_localoffset"] - -rfc3339_regex = re.compile( - r"^(\d\d\d\d)\-(\d\d)\-(\d\d)T" - r"(\d\d):(\d\d):(\d\d)(\.\d+)?(Z|([+\-])(\d\d):(\d\d))$") - - -def validate_rfc3339(datestring): - """Check an RFC3339 string is valid via a regex and some range checks""" - - m = rfc3339_regex.match(datestring) - if m is None: - return False - - groups = m.groups() - - year, month, day, hour, minute, second = [int(i) for i in groups[:6]] - - if not 1 <= year <= 9999: - # Have to reject this, unfortunately (despite it being OK by rfc3339): - # calendar.timegm/calendar.monthrange can't cope (since datetime can't) - return False - - if not 1 <= month <= 12: - return False - - (_, max_day) = calendar.monthrange(year, month) - if not 1 <= day <= max_day: - return False - - if not (0 <= hour <= 23 and 0 <= minute <= 59 and 0 <= second <= 59): - # forbid leap seconds :-(. See README - return False - - if groups[7] != "Z": - (offset_sign, offset_hours, offset_mins) = groups[8:] - if not (0 <= int(offset_hours) <= 23 and 0 <= int(offset_mins) <= 59): - return False - - # all OK - return True - - -class InvalidRFC3339Error(ValueError): - """Subclass of ValueError thrown by rfc3339_to_timestamp""" - pass - - -def rfc3339_to_timestamp(datestring): - """Convert an RFC3339 date-time string to a UTC UNIX timestamp""" - - if not validate_rfc3339(datestring): - raise InvalidRFC3339Error - - groups = rfc3339_regex.match(datestring).groups() - - time_tuple = [int(p) for p in groups[:6]] - timestamp = calendar.timegm(time_tuple) - - seconds_part = groups[6] - if seconds_part is not None: - timestamp += float("0" + seconds_part) - - if groups[7] != "Z": - (offset_sign, offset_hours, offset_mins) = groups[8:] - offset_seconds = int(offset_hours) * 3600 + int(offset_mins) * 60 - if offset_sign == '-': - offset_seconds = -offset_seconds - timestamp -= offset_seconds - - return timestamp - - -def _seconds_and_microseconds(timestamp): - """ - Split a floating point timestamp into an integer number of seconds since - the epoch, and an integer number of microseconds (having rounded to the - nearest microsecond). - - If `_seconds_and_microseconds(x) = (y, z)` then the following holds (up to - the error introduced by floating point operations): - - * `x = y + z / 1_000_000.` - * `0 <= z < 1_000_000.` - """ - - if isinstance(timestamp, int): - return (timestamp, 0) - else: - timestamp_us = int(round(timestamp * 1e6)) - return divmod(timestamp_us, 1000000) - -def _make_datestring_start(time_tuple, microseconds): - ds_format = "{0:04d}-{1:02d}-{2:02d}T{3:02d}:{4:02d}:{5:02d}" - datestring = ds_format.format(*time_tuple) - - seconds_part_str = "{0:06d}".format(microseconds) - # There used to be a bug here where it could be 1000000 - assert len(seconds_part_str) == 6 and seconds_part_str[0] != '-' - seconds_part_str = seconds_part_str.rstrip("0") - if seconds_part_str != "": - datestring += "." + seconds_part_str - - return datestring - - -def timestamp_to_rfc3339_utcoffset(timestamp): - """Convert a UTC UNIX timestamp to RFC3339, with the offset as 'Z'""" - - seconds, microseconds = _seconds_and_microseconds(timestamp) - - time_tuple = time.gmtime(seconds) - datestring = _make_datestring_start(time_tuple, microseconds) - datestring += "Z" - - assert abs(rfc3339_to_timestamp(datestring) - timestamp) < 0.000001 - return datestring - - -def timestamp_to_rfc3339_localoffset(timestamp): - """ - Convert a UTC UNIX timestamp to RFC3339, using the local offset. - - localtime() provides the time parts. The difference between gmtime and - localtime tells us the offset. - """ - - seconds, microseconds = _seconds_and_microseconds(timestamp) - - time_tuple = time.localtime(seconds) - datestring = _make_datestring_start(time_tuple, microseconds) - - gm_time_tuple = time.gmtime(seconds) - offset = calendar.timegm(time_tuple) - calendar.timegm(gm_time_tuple) - - if abs(offset) % 60 != 0: - raise ValueError("Your local offset is not a whole minute") - - offset_minutes = abs(offset) // 60 - offset_hours = offset_minutes // 60 - offset_minutes %= 60 - - offset_string = "{0:02d}:{1:02d}".format(offset_hours, offset_minutes) - - if offset < 0: - datestring += "-" - else: - datestring += "+" - - datestring += offset_string - assert abs(rfc3339_to_timestamp(datestring) - timestamp) < 0.000001 - - return datestring - - -def now_to_rfc3339_utcoffset(integer=True): - """Convert the current time to RFC3339, with the offset as 'Z'""" - - timestamp = time.time() - if integer: - timestamp = int(timestamp) - return timestamp_to_rfc3339_utcoffset(timestamp) - - -def now_to_rfc3339_localoffset(integer=True): - """Convert the current time to RFC3339, using the local offset.""" - - timestamp = time.time() - if integer: - timestamp = int(timestamp) - return timestamp_to_rfc3339_localoffset(timestamp) diff --git a/pipenv/vendor/timestamp.py b/pipenv/vendor/timestamp.py deleted file mode 100644 index effb3326..00000000 --- a/pipenv/vendor/timestamp.py +++ /dev/null @@ -1,9 +0,0 @@ -import sys - -def timestamp(d=None): - import datetime - import time - return int(time.mktime(d.timetuple()) * 1000) if d else int(time.time() * 1000) - -sys.modules[__name__] = timestamp - From 6bfa525fd3151bd4c6d4c5c7fea68108c6cc97e1 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Mon, 16 Apr 2018 15:30:00 +0800 Subject: [PATCH 2/3] Add tests for prettytoml datetime --- Pipfile | 1 + Pipfile.lock | 156 +++++--------------------------------- tests/unit/test_vendor.py | 48 +++++++++++- 3 files changed, 63 insertions(+), 142 deletions(-) diff --git a/Pipfile b/Pipfile index 494bfadb..1de46551 100644 --- a/Pipfile +++ b/Pipfile @@ -13,6 +13,7 @@ pytest-tap = "*" flaky = "*" stdeb = {version="*", markers="sys_platform == 'linux'"} white = {version="*", markers="python_version >= '3.6'"} +pytz = "*" [packages] diff --git a/Pipfile.lock b/Pipfile.lock index 29bc7eb0..666cca79 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "5941b36256503b9729e927f3249a366748da5c353b59c1e32ca7fd919b31a4d6" + "sha256": "bc81bb0e64d7ed1eed2627819b4a806d8cba554c1e0398191ba1ba32a216ed2a" }, "pipfile-spec": 6, "requires": {}, @@ -29,13 +29,6 @@ ], "version": "==1.4" }, - "asn1crypto": { - "hashes": [ - "sha256:2f1adbb7546ed199e3c90ef23ec95c5cf3585bac7d11fb7eb562a3fe89c64e87", - "sha256:9d5c20441baf0cb60a4ac34cc447c6c189024b6b4c6cd7877034f4965c464e49" - ], - "version": "==0.24.0" - }, "attrs": { "hashes": [ "sha256:1c7960ccfd6a005cd9f7ba884e6316b5e430a3f1a6c37c5f87d8b43f83b54ec9", @@ -57,39 +50,6 @@ ], "version": "==2018.1.18" }, - "cffi": { - "hashes": [ - "sha256:151b7eefd035c56b2b2e1eb9963c90c6302dc15fbd8c1c0a83a163ff2c7d7743", - "sha256:1553d1e99f035ace1c0544050622b7bc963374a00c467edafac50ad7bd276aef", - "sha256:1b0493c091a1898f1136e3f4f991a784437fac3673780ff9de3bcf46c80b6b50", - "sha256:2ba8a45822b7aee805ab49abfe7eec16b90587f7f26df20c71dd89e45a97076f", - "sha256:3c85641778460581c42924384f5e68076d724ceac0f267d66c757f7535069c93", - "sha256:3eb6434197633b7748cea30bf0ba9f66727cdce45117a712b29a443943733257", - "sha256:4c91af6e967c2015729d3e69c2e51d92f9898c330d6a851bf8f121236f3defd3", - "sha256:770f3782b31f50b68627e22f91cb182c48c47c02eb405fd689472aa7b7aa16dc", - "sha256:79f9b6f7c46ae1f8ded75f68cf8ad50e5729ed4d590c74840471fc2823457d04", - "sha256:7a33145e04d44ce95bcd71e522b478d282ad0eafaf34fe1ec5bbd73e662f22b6", - "sha256:857959354ae3a6fa3da6651b966d13b0a8bed6bbc87a0de7b38a549db1d2a359", - "sha256:87f37fe5130574ff76c17cab61e7d2538a16f843bb7bca8ebbc4b12de3078596", - "sha256:95d5251e4b5ca00061f9d9f3d6fe537247e145a8524ae9fd30a2f8fbce993b5b", - "sha256:9d1d3e63a4afdc29bd76ce6aa9d58c771cd1599fbba8cf5057e7860b203710dd", - "sha256:a36c5c154f9d42ec176e6e620cb0dd275744aa1d804786a71ac37dc3661a5e95", - "sha256:ae5e35a2c189d397b91034642cb0eab0e346f776ec2eb44a49a459e6615d6e2e", - "sha256:b0f7d4a3df8f06cf49f9f121bead236e328074de6449866515cea4907bbc63d6", - "sha256:b75110fb114fa366b29a027d0c9be3709579602ae111ff61674d28c93606acca", - "sha256:ba5e697569f84b13640c9e193170e89c13c6244c24400fc57e88724ef610cd31", - "sha256:be2a9b390f77fd7676d80bc3cdc4f8edb940d8c198ed2d8c0be1319018c778e1", - "sha256:d5d8555d9bfc3f02385c1c37e9f998e2011f0db4f90e250e5bc0c0a85a813085", - "sha256:e55e22ac0a30023426564b1059b035973ec82186ddddbac867078435801c7801", - "sha256:e90f17980e6ab0f3c2f3730e56d1fe9bcba1891eeea58966e89d352492cc74f4", - "sha256:ecbb7b01409e9b782df5ded849c178a0aa7c906cf8c5a67368047daab282b184", - "sha256:ed01918d545a38998bfa5902c7c00e0fee90e957ce036a4000a88e3fe2264917", - "sha256:edabd457cd23a02965166026fd9bfd196f4324fe6032e866d0f3bd0301cd486f", - "sha256:fdf1c1dc5bafc32bc5d08b054f94d659422b05aba244d6be4ddc1c72d9aa70fb" - ], - "markers": "platform_python_implementation != 'pypy'", - "version": "==1.11.5" - }, "chardet": { "hashes": [ "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", @@ -105,43 +65,6 @@ "index": "pypi", "version": "==6.7" }, - "colorama": { - "hashes": [ - "sha256:463f8483208e921368c9f306094eb6f725c6ca42b0f97e313cb5d5512459feda", - "sha256:48eb22f4f8461b1df5734a074b57042430fb06e1d61bd1e11b078c0fe6d7a1f1" - ], - "markers": "sys_platform == 'win32'", - "version": "==0.3.9" - }, - "configparser": { - "hashes": [ - "sha256:5308b47021bc2340965c371f0f058cc6971a04502638d4244225c49d80db273a" - ], - "markers": "python_version < '3.2'", - "version": "==3.5.0" - }, - "cryptography": { - "hashes": [ - "sha256:3f3b65d5a16e6b52fba63dc860b62ca9832f51f1a2ae5083c78b6840275f12dd", - "sha256:551a3abfe0c8c6833df4192a63371aa2ff43afd8f570ed345d31f251d78e7e04", - "sha256:5cb990056b7cadcca26813311187ad751ea644712022a3976443691168781b6f", - "sha256:60bda7f12ecb828358be53095fc9c6edda7de8f1ef571f96c00b2363643fa3cd", - "sha256:6fef51ec447fe9f8351894024e94736862900d3a9aa2961528e602eb65c92bdb", - "sha256:77d0ad229d47a6e0272d00f6bf8ac06ce14715a9fd02c9a97f5a2869aab3ccb2", - "sha256:808fe471b1a6b777f026f7dc7bd9a4959da4bfab64972f2bbe91e22527c1c037", - "sha256:9b62fb4d18529c84b961efd9187fecbb48e89aa1a0f9f4161c61b7fc42a101bd", - "sha256:9e5bed45ec6b4f828866ac6a6bedf08388ffcfa68abe9e94b34bb40977aba531", - "sha256:9fc295bf69130a342e7a19a39d7bbeb15c0bcaabc7382ec33ef3b2b7d18d2f63", - "sha256:abd070b5849ed64e6d349199bef955ee0ad99aefbad792f0c587f8effa681a5e", - "sha256:ba6a774749b6e510cffc2fb98535f717e0e5fd91c7c99a61d223293df79ab351", - "sha256:c332118647f084c983c6a3e1dba0f3bcb051f69d12baccac68db8d62d177eb8a", - "sha256:d6f46e862ee36df81e6342c2177ba84e70f722d9dc9c6c394f9f1f434c4a5563", - "sha256:db6013746f73bf8edd9c3d1d3f94db635b9422f503db3fc5ef105233d4c011ab", - "sha256:f57008eaff597c69cf692c3518f6d4800f0309253bb138b526a37fe9ef0c7471", - "sha256:f6c821ac253c19f2ad4c8691633ae1d1a17f120d5b01ea1d256d7b602bc59887" - ], - "version": "==2.2.2" - }, "docutils": { "hashes": [ "sha256:02aec4bd92ab067f6ff27a38a38a41173bf01bed8f89157768c1573f53e474a6", @@ -150,16 +73,6 @@ ], "version": "==0.14" }, - "enum34": { - "hashes": [ - "sha256:2d81cbbe0e73112bdfe6ef8576f2238f2ba27dd0d55752a776c41d38b7da2850", - "sha256:644837f692e5f550741432dd3f223bbb9852018674981b1664e5dc339387588a", - "sha256:6bd0f6ad48ec2aa117d3d141940d484deccda84d4fcd884f5c3d93c23ecd8c79", - "sha256:8ad8c4783bf61ded74527bffb48ed9b54166685e4230386a9ed9b1279e2df5b1" - ], - "markers": "python_version < '3'", - "version": "==1.1.6" - }, "execnet": { "hashes": [ "sha256:a7a84d5fa07a089186a329528f127c9d73b9de57f1a1131b82bb5320ee651f6a", @@ -190,14 +103,6 @@ ], "version": "==0.12.2" }, - "funcsigs": { - "hashes": [ - "sha256:330cc27ccbf7f1e992e69fef78261dc7c6569012cf397db8d3de0234e6c937ca", - "sha256:a7bb0f2cf3a3fd1ab2732cb49eba4252c2af4240442415b4abce3b87022a8f50" - ], - "markers": "python_version < '3.0'", - "version": "==1.0.2" - }, "idna": { "hashes": [ "sha256:2c6a5de3089009e3da7c5dde64a141dbc8551d5b7f6cf4ed7c2568d0cc520a8f", @@ -212,13 +117,6 @@ ], "version": "==1.0.0" }, - "ipaddress": { - "hashes": [ - "sha256:200d8686011d470b5e4de207d803445deee427455cd0cb7c982b68cf82524f81" - ], - "markers": "python_version < '3'", - "version": "==1.0.19" - }, "itsdangerous": { "hashes": [ "sha256:cbb3fcf8d3e33df861709ecaf89d9e6629cff0a217bc2848f1b41cd30d360519" @@ -261,12 +159,6 @@ ], "version": "==4.1.0" }, - "ordereddict": { - "hashes": [ - "sha256:1c35b4ac206cef2d24816c89f89cf289dd3d38cf7c449bb3fab7bf6d43f01b1f" - ], - "version": "==1.1" - }, "pathlib2": { "hashes": [ "sha256:24e0b33e1333b55e73c9d1e9a8342417d519f7789a9d3b440f4acd00ea45157e", @@ -277,10 +169,10 @@ }, "pbr": { "hashes": [ - "sha256:56b7a8ba7d64bf6135a9dfefb85a80d95924b3fde5ed6343a1a1d464a040dae3", - "sha256:de75cf1d510542c746beeff66b52241eb12c8f95f2ef846ee50ed5d72392caa4" + "sha256:4e8a0ed6a8705a26768f4c3da26026013b157821fe5f95881599556ea9d91c19", + "sha256:dae4aaa78eafcad10ce2581fc34d694faa616727837fd8e55c1a00951ad6744f" ], - "version": "==4.0.1" + "version": "==4.0.2" }, "pipenv": { "editable": true, @@ -295,7 +187,10 @@ }, "pluggy": { "hashes": [ - "sha256:7f8ae7f5bdf75671a718d2daf0a64b7885f74510bcd98b1a0bb420eb9a9d0cff" + "sha256:714306e9b9a7b24ee4c1e3ff6463d7f652cdd30f4693121b31572e2fe1fdaea3", + "sha256:7f8ae7f5bdf75671a718d2daf0a64b7885f74510bcd98b1a0bb420eb9a9d0cff", + "sha256:d345c8fe681115900d6da8d048ba67c25df42973bda370783cd58826442dcd7c", + "sha256:e160a7fcf25762bb60efc7e171d4497ff1d8d2d75a3d0df7a21b76821ecbf5c5" ], "version": "==0.6.0" }, @@ -308,17 +203,13 @@ }, "pycodestyle": { "hashes": [ + "sha256:1ec08a51c901dfe44921576ed6e4c1f5b7ecbad403f871397feedb5eb8e4fa14", + "sha256:5ff2fbcbab997895ba9ead77e1b38b3ebc2e5c3b8a6194ef918666e4c790a00e", "sha256:682256a5b318149ca0d2a9185d365d8864a768a28db66a84a2ea946bcc426766", "sha256:6c4245ade1edfad79c3446fadfc96b0de2759662dc29d07d80a6f27ad1ca6ba9" ], "version": "==2.3.1" }, - "pycparser": { - "hashes": [ - "sha256:99a8ca03e29851d96616ad0404b4aad7d9ee16f25c9f9708a11faf2810f7b226" - ], - "version": "==2.18" - }, "pyflakes": { "hashes": [ "sha256:08bd6a50edf8cffa9fa09a463063c425ecaaf10d1eb0335a7e8b1401aef89e6f", @@ -333,13 +224,6 @@ ], "version": "==2.2.0" }, - "pyopenssl": { - "hashes": [ - "sha256:07a2de1a54de07448732a81e38a55df7da109b2f47f599f8bb35b0cbec69d4bd", - "sha256:2c10cfba46a52c0b0950118981d61e72c1e5b1aac451ca1bc77de1a679456773" - ], - "version": "==17.5.0" - }, "pytest": { "hashes": [ "sha256:6266f87ab64692112e5477eba395cfedda53b1933ccd29478e671e73b420c19c", @@ -377,17 +261,11 @@ }, "pytz": { "hashes": [ - "sha256:07edfc3d4d2705a20a6e99d97f0c4b61c800b8232dc1c04d87e8554f130148dd", - "sha256:3a47ff71597f821cd84a162e71593004286e5be07a340fd462f0d33a760782b5", - "sha256:410bcd1d6409026fbaa65d9ed33bf6dd8b1e94a499e32168acfc7b332e4095c0", - "sha256:5bd55c744e6feaa4d599a6cbd8228b4f8f9ba96de2c38d56f08e534b3c9edf0d", - "sha256:61242a9abc626379574a166dc0e96a66cd7c3b27fc10868003fa210be4bff1c9", - "sha256:887ab5e5b32e4d0c86efddd3d055c1f363cbaa583beb8da5e22d2fa2f64d51ef", - "sha256:ba18e6a243b3625513d85239b3e49055a2f0318466e0b8a92b8fb8ca7ccdf55f", - "sha256:ed6509d9af298b7995d69a440e2822288f2eca1681b8cce37673dbb10091e5fe", - "sha256:f93ddcdd6342f94cea379c73cddb5724e0d6d0a1c91c9bdef364dc0368ba4fda" + "sha256:65ae0c8101309c45772196b21b74c46b2e5d11b6275c45d251b150d5da334555", + "sha256:c06425302f2cf668f1bba7a0a03f3c1d34d4ebeef2c72003da308b3947c7f749" ], - "version": "==2018.3" + "index": "pypi", + "version": "==2018.4" }, "requests": { "hashes": [ @@ -450,10 +328,10 @@ }, "tqdm": { "hashes": [ - "sha256:4f2eb1d14804caf7095500fe11da0e481a47af912e7b57c93f886ac3c40a49dd", - "sha256:91ac47ec2ba6bb92b7ba37706f4dea37019ddd784b22fd279a4b12d93327191d" + "sha256:597e7526c85df881d51e094360181a84533aede1cb3f5a1cada8bbd4de557efd", + "sha256:fe3d218d5b61993d415aa2a9db6dd64c0e4cefb90164ebb197ef3b1d99f531dc" ], - "version": "==4.20.0" + "version": "==4.23.0" }, "twine": { "hashes": [ diff --git a/tests/unit/test_vendor.py b/tests/unit/test_vendor.py index a0e377fa..915af863 100644 --- a/tests/unit/test_vendor.py +++ b/tests/unit/test_vendor.py @@ -1,14 +1,21 @@ -# Make sure we use the patched packages. +# We need to import the patched packages directly from sys.path, so the +# identity checks can pass. import pipenv # noqa + +import datetime import os -from prettytoml import lexer +import pytest +import pytz + +from pipfile.api import PipfileParser +from prettytoml import lexer, tokens from prettytoml.elements.atomic import AtomicElement from prettytoml.elements.metadata import ( WhitespaceElement, PunctuationElement, CommentElement ) from prettytoml.elements.table import TableElement -from pipenv.patched.pipfile.api import PipfileParser +from prettytoml.tokens.py2toml import create_primitive_token def test_table(): @@ -62,3 +69,38 @@ class TestPipfileParser: assert parsed_dict["list"][1] == {} assert parsed_dict["bool"] is True assert parsed_dict["none"] is None + + +@pytest.mark.parametrize('dt, content', [ + ( # Date. + datetime.date(1992, 8, 19), + '1992-08-19', + ), + ( # Naive time. + datetime.time(15, 10), + '15:10:00', + ), + ( # Aware time in UTC. + datetime.time(15, 10, tzinfo=pytz.UTC), + '15:10:00Z', + ), + ( # Aware local time. + datetime.time(15, 10, tzinfo=pytz.FixedOffset(8 * 60)), + '15:10:00+08:00', + ), + ( # Naive datetime. + datetime.datetime(1992, 8, 19, 15, 10), + '1992-08-19T15:10:00', + ), + ( # Aware datetime in UTC. + datetime.datetime(1992, 8, 19, 15, 10, tzinfo=pytz.UTC), + '1992-08-19T15:10:00Z', + ), + ( # Aware local datetime. + datetime.datetime(1992, 8, 19, 15, 10, tzinfo=pytz.FixedOffset(8 * 60)), + '1992-08-19T15:10:00+08:00', + ), +]) +def test_token_date(dt, content): + token = create_primitive_token(dt) + assert token == tokens.Token(tokens.TYPE_DATE, content) From eaed1811480ef5dbf8cfe0b59f9f78bc6c29b689 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Mon, 16 Apr 2018 19:25:16 -0400 Subject: [PATCH 3/3] Update lockfile to include win32 deps Signed-off-by: Dan Ryan --- Pipfile.lock | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Pipfile.lock b/Pipfile.lock index 29bc7eb0..b6a4737b 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -277,10 +277,10 @@ }, "pbr": { "hashes": [ - "sha256:56b7a8ba7d64bf6135a9dfefb85a80d95924b3fde5ed6343a1a1d464a040dae3", - "sha256:de75cf1d510542c746beeff66b52241eb12c8f95f2ef846ee50ed5d72392caa4" - ], - "version": "==4.0.1" + "sha256:4e8a0ed6a8705a26768f4c3da26026013b157821fe5f95881599556ea9d91c19", + "sha256:dae4aaa78eafcad10ce2581fc34d694faa616727837fd8e55c1a00951ad6744f" + ], + "version": "==4.0.2" }, "pipenv": { "editable": true, @@ -295,6 +295,9 @@ }, "pluggy": { "hashes": [ + "sha256:714306e9b9a7b24ee4c1e3ff6463d7f652cdd30f4693121b31572e2fe1fdaea3", + "sha256:d345c8fe681115900d6da8d048ba67c25df42973bda370783cd58826442dcd7c", + "sha256:e160a7fcf25762bb60efc7e171d4497ff1d8d2d75a3d0df7a21b76821ecbf5c5", "sha256:7f8ae7f5bdf75671a718d2daf0a64b7885f74510bcd98b1a0bb420eb9a9d0cff" ], "version": "==0.6.0" @@ -308,6 +311,8 @@ }, "pycodestyle": { "hashes": [ + "sha256:1ec08a51c901dfe44921576ed6e4c1f5b7ecbad403f871397feedb5eb8e4fa14", + "sha256:5ff2fbcbab997895ba9ead77e1b38b3ebc2e5c3b8a6194ef918666e4c790a00e", "sha256:682256a5b318149ca0d2a9185d365d8864a768a28db66a84a2ea946bcc426766", "sha256:6c4245ade1edfad79c3446fadfc96b0de2759662dc29d07d80a6f27ad1ca6ba9" ], @@ -450,11 +455,11 @@ }, "tqdm": { "hashes": [ - "sha256:4f2eb1d14804caf7095500fe11da0e481a47af912e7b57c93f886ac3c40a49dd", - "sha256:91ac47ec2ba6bb92b7ba37706f4dea37019ddd784b22fd279a4b12d93327191d" - ], - "version": "==4.20.0" - }, + "sha256:597e7526c85df881d51e094360181a84533aede1cb3f5a1cada8bbd4de557efd", + "sha256:fe3d218d5b61993d415aa2a9db6dd64c0e4cefb90164ebb197ef3b1d99f531dc" + ], + "version": "==4.23.0" + } "twine": { "hashes": [ "sha256:08eb132bbaec40c6d25b358f546ec1dc96ebd2638a86eea68769d9e67fe2b129",