Skip to content

Commit

Permalink
(Lint everything through ruff format.)
Browse files Browse the repository at this point in the history
  • Loading branch information
blais committed Jun 19, 2024
1 parent 517b712 commit e894c91
Show file tree
Hide file tree
Showing 29 changed files with 1,134 additions and 906 deletions.
1 change: 1 addition & 0 deletions beanprice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,6 @@
historical data for its CURRENCY:* instruments.
"""

__copyright__ = "Copyright (C) 2015-2020 Martin Blais"
__license__ = "GNU GPLv2"
12 changes: 6 additions & 6 deletions beanprice/date_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Date utilities.
"""
"""Date utilities."""

__copyright__ = "Copyright (C) 2020 Martin Blais"
__license__ = "GNU GPLv2"

Expand Down Expand Up @@ -39,14 +39,14 @@ def intimezone(tz_value: str):
Returns:
A contextmanager in the given timezone locale.
"""
tz_old = os.environ.get('TZ', None)
os.environ['TZ'] = tz_value
tz_old = os.environ.get("TZ", None)
os.environ["TZ"] = tz_value
time.tzset()
try:
yield
finally:
if tz_old is None:
del os.environ['TZ']
del os.environ["TZ"]
else:
os.environ['TZ'] = tz_old
os.environ["TZ"] = tz_old
time.tzset()
17 changes: 8 additions & 9 deletions beanprice/date_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@


class TestDateUtils(unittest.TestCase):

def test_parse_date_liberally(self):
const_date = datetime.date(2014, 12, 7)
test_cases = (
('12/7/2014',),
('7-Dec-2014',),
('7/12/2014', {'parserinfo': dateutil.parser.parserinfo(dayfirst=True)}),
('12/7', {'default': datetime.datetime(2014, 1, 1)}),
('7.12.2014', {'dayfirst': True}),
('14 12 7', {'yearfirst': True}),
('Transaction of 7th December 2014', {'fuzzy': True}),
("12/7/2014",),
("7-Dec-2014",),
("7/12/2014", {"parserinfo": dateutil.parser.parserinfo(dayfirst=True)}),
("12/7", {"default": datetime.datetime(2014, 1, 1)}),
("7.12.2014", {"dayfirst": True}),
("14 12 7", {"yearfirst": True}),
("Transaction of 7th December 2014", {"fuzzy": True}),
)
for case in test_cases:
if len(case) == 2:
Expand All @@ -40,5 +39,5 @@ def test_intimezone(self):
self.assertNotEqual(now_tokyo, now_nyc)


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
4 changes: 2 additions & 2 deletions beanprice/net_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Network utilities.
"""
"""Network utilities."""

__copyright__ = "Copyright (C) 2015-2016 Martin Blais"
__license__ = "GNU GPLv2"

Expand Down
23 changes: 11 additions & 12 deletions beanprice/net_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,29 @@


class TestRetryingUrlopen(unittest.TestCase):

def test_success_200(self):
response = http.client.HTTPResponse(mock.MagicMock())
response.status = 200
with mock.patch('urllib.request.urlopen', return_value=response):
self.assertIs(net_utils.retrying_urlopen('http://nowhere.com'), response)
with mock.patch("urllib.request.urlopen", return_value=response):
self.assertIs(net_utils.retrying_urlopen("http://nowhere.com"), response)

def test_success_other(self):
response = http.client.HTTPResponse(mock.MagicMock())
with mock.patch('urllib.request.urlopen', return_value=response):
self.assertIsNone(net_utils.retrying_urlopen('http://nowhere.com'))
with mock.patch("urllib.request.urlopen", return_value=response):
self.assertIsNone(net_utils.retrying_urlopen("http://nowhere.com"))

def test_timeout_once(self):
response = http.client.HTTPResponse(mock.MagicMock())
response.status = 200
with mock.patch('urllib.request.urlopen',
side_effect=[None, response]):
self.assertIs(net_utils.retrying_urlopen('http://nowhere.com'), response)
with mock.patch("urllib.request.urlopen", side_effect=[None, response]):
self.assertIs(net_utils.retrying_urlopen("http://nowhere.com"), response)

def test_max_retry(self):
with mock.patch('urllib.request.urlopen',
side_effect=[None, None, None, None, None, None]):
self.assertIsNone(net_utils.retrying_urlopen('http://nowhere.com'))
with mock.patch(
"urllib.request.urlopen", side_effect=[None, None, None, None, None, None]
):
self.assertIsNone(net_utils.retrying_urlopen("http://nowhere.com"))


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit e894c91

Please sign in to comment.