Skip to content

Commit ca5d74d

Browse files
authored
Merge pull request #1498 from cmu-delphi/pyclient_fix_fix
fix: simplify client version check
2 parents 21c7df6 + 51ee2f1 commit ca5d74d

File tree

2 files changed

+4
-24
lines changed

2 files changed

+4
-24
lines changed

integrations/client/test_delphi_epidata.py

-13
Original file line numberDiff line numberDiff line change
@@ -318,27 +318,14 @@ def json(self): return json.loads(self.content)
318318
get.reset_mock()
319319
get.return_value = MockJson(b'{"info": {"version": "0.0.1"}}', 200)
320320

321-
# "back up" the value of this private class var and replace w/ default
322-
# so the ._version_check() method runs unencumbered:
323-
e_vdc__save = Epidata._version_checked
324-
Epidata._version_checked = False
325-
# run version check:
326321
Epidata._version_check()
327-
# "restore" class var:
328-
Epidata._version_checked = e_vdc__save
329322

330323
captured = self.capsys.readouterr()
331324
output = captured.err.splitlines()
332325
self.assertEqual(len(output), 1)
333326
self.assertIn("Client version not up to date", output[0])
334327
self.assertIn("\'latest_version\': \'0.0.1\'", output[0])
335328

336-
@patch('delphi.epidata.client.delphi_epidata.Epidata._version_check')
337-
def test_version_check_once(self, version_check):
338-
"""Test that the _version_check() function is only called once on initial module import."""
339-
from delphi.epidata.client.delphi_epidata import Epidata
340-
version_check.assert_not_called()
341-
342329
def test_geo_value(self):
343330
"""test different variants of geo types: single, *, multi."""
344331

src/client/delphi_epidata.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,18 @@ class Epidata:
4646
debug = False # if True, prints extra logging statements
4747
sandbox = False # if True, will not execute any queries
4848

49-
_version_checked = False
50-
5149
@staticmethod
5250
def log(evt, **kwargs):
5351
kwargs['event'] = evt
5452
kwargs['timestamp'] = time.strftime("%Y-%m-%d %H:%M:%S %z")
5553
return sys.stderr.write(str(kwargs) + "\n")
5654

57-
# Check that this client's version matches the most recent available.
58-
# This is indended to run just once per program execution, on initial module load.
59-
# See the bottom of this file for the ultimate call to this method.
55+
# Check that this client's version matches the most recent available. This
56+
# is run just once per program execution, on initial module load (see the
57+
# bottom of the file). This is a function of how Python's module system
58+
# works: https://docs.python.org/3/reference/import.html#the-module-cache
6059
@staticmethod
6160
def _version_check():
62-
if Epidata._version_checked:
63-
# already done; nothing to do!
64-
return
65-
66-
Epidata._version_checked = True
67-
6861
try:
6962
request = requests.get('https://pypi.org/pypi/delphi-epidata/json', timeout=5)
7063
latest_version = request.json()['info']['version']

0 commit comments

Comments
 (0)