Skip to content

Commit

Permalink
Remove use of pytz
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Dec 6, 2023
1 parent a88cc73 commit 0be2bfe
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 90 deletions.
34 changes: 2 additions & 32 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ repository = "http://github.com/rapidpro/rapidpro-python"

[tool.poetry.dependencies]
python = "^3.9"
pytz = "*"
requests = "^2.25.0"
iso8601 = "^0.1.13"

Expand Down
17 changes: 8 additions & 9 deletions temba_client/tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import codecs
import datetime
import json
import unittest
from datetime import datetime, timedelta, timezone as tzone, tzinfo

import pytz
import requests
from requests.structures import CaseInsensitiveDict

Expand Down Expand Up @@ -79,18 +78,18 @@ def assertRequest(self, mock, method, endpoint, **kwargs):


class UtilsTest(TembaTest):
class TestTZ(datetime.tzinfo):
class TestTZ(tzinfo):
def utcoffset(self, dt):
return datetime.timedelta(hours=-5)
return timedelta(hours=-5)

def test_format_iso8601(self):
d = datetime.datetime(2014, 1, 2, 3, 4, 5, 6, UtilsTest.TestTZ())
d = datetime(2014, 1, 2, 3, 4, 5, 6, UtilsTest.TestTZ())
self.assertEqual(format_iso8601(d), "2014-01-02T08:04:05.000006Z")
# it should return None when no datetime given
self.assertIs(format_iso8601(None), None)

def test_parse_iso8601(self):
dt = datetime.datetime(2014, 1, 2, 3, 4, 5, 0, pytz.UTC)
dt = datetime(2014, 1, 2, 3, 4, 5, 0, tzone.utc)
self.assertEqual(parse_iso8601("2014-01-02T03:04:05.000000Z"), dt)
self.assertEqual(parse_iso8601("2014-01-02T03:04:05.000000+00:00"), dt)
self.assertEqual(parse_iso8601("2014-01-02T05:04:05.000000+02:00"), dt)
Expand All @@ -99,7 +98,7 @@ def test_parse_iso8601(self):
self.assertEqual(parse_iso8601("2014-01-02T03:04:05"), dt)
self.assertEqual(parse_iso8601(None), None)

d = datetime.datetime(2014, 1, 2, 0, 0, 0, 0, pytz.UTC)
d = datetime(2014, 1, 2, 0, 0, 0, 0, tzone.utc)
self.assertEqual(parse_iso8601("2014-01-02"), d)


Expand Down Expand Up @@ -218,7 +217,7 @@ def test_deserialize(self):
)
self.assertEqual(obj.foo, "a")
self.assertEqual(obj.bar, 123)
self.assertEqual(obj.doh, datetime.datetime(2014, 1, 2, 3, 4, 5, 0, pytz.UTC))
self.assertEqual(obj.doh, datetime(2014, 1, 2, 3, 4, 5, 0, tzone.utc))
self.assertEqual(obj.gem.zed, "c")
self.assertEqual(len(obj.hum), 1)
self.assertEqual(obj.hum[0].zed, "b")
Expand All @@ -237,7 +236,7 @@ def test_serialize(self):
obj = TestType.create(
foo="a",
bar=123,
doh=datetime.datetime(2014, 1, 2, 3, 4, 5, 0, pytz.UTC),
doh=datetime(2014, 1, 2, 3, 4, 5, 0, tzone.utc),
gem=TestSubType.create(zed="a"),
hum=[TestSubType.create(zed="b")],
meh={"a": TestSubType.create(zed="c"), "b": TestSubType.create(zed="d")},
Expand Down
4 changes: 2 additions & 2 deletions temba_client/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from datetime import timezone as tzone

import iso8601
import pytz
import requests


Expand All @@ -22,7 +22,7 @@ def format_iso8601(value):
if value is None:
return None

return str(value.astimezone(pytz.UTC).strftime("%Y-%m-%dT%H:%M:%S.%fZ"))
return str(value.astimezone(tzone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ"))


def request(method, url, **kwargs): # pragma: no cover
Expand Down
Loading

0 comments on commit 0be2bfe

Please sign in to comment.