Repository: openaddresses/machine
Pull request #462 (2016-11-27 04:05:59)

Using run state to correctly determine code version
Version should have been coming from run state this whole time.


Patch:
diff --git a/openaddr/ci/objects.py b/openaddr/ci/objects.py
index d50d486..dbeb153 100644
--- a/openaddr/ci/objects.py
+++ b/openaddr/ci/objects.py
@@ -1,6 +1,5 @@
 import logging; _L = logging.getLogger('openaddr.ci.objects')
 
-from .. import __version__
 import json, pickle
 
 # Todo: make this a Python 3 enum
@@ -308,7 +307,7 @@ def set_run(db, run_id, filename, file_id, content_b64, run_state, run_status,
                   WHERE id = %s''',
                (filename, content_b64, file_id,
                run_state.to_json(), run_status, worker_id,
-               __version__, job_id, commit_sha, is_merged,
+               run_state.version, job_id, commit_sha, is_merged,
                set_id, run_id))
 
 def copy_run(db, run_id, job_id, commit_sha, set_id):


Test patch:
diff --git a/openaddr/tests/ci.py b/openaddr/tests/ci.py
index 42a73ec..7cdfc30 100644
--- a/openaddr/tests/ci.py
+++ b/openaddr/tests/ci.py
@@ -1,8 +1,6 @@
 # coding=utf8
 from __future__ import print_function
 
-from .. import __version__
-
 from os import environ, remove, stat, close, utime
 from os.path import join, splitext
 from shutil import rmtree
@@ -357,7 +355,7 @@ class TestObjects (unittest.TestCase):
     def test_set_run(self):
         ''' Check behavior of objects.add_set()
         '''
-        set_run(self.db, 456, '', '', b'', RunState({}), True, 'xyz', '', '', False, 123)
+        set_run(self.db, 456, '', '', b'', RunState({'version': 'x.y.z'}), True, 'xyz', '', '', False, 123)
 
         self.db.execute.assert_called_once_with(
                '''UPDATE runs SET
@@ -367,8 +365,8 @@ class TestObjects (unittest.TestCase):
                   is_merged = %s, set_id = %s, datetime_tz = NOW()
                   WHERE id = %s''',
                   ('', b'', '',
-                   '{}', True, '',
-                   __version__, 'xyz', '', False,
+                   '{"version": "x.y.z"}', True, '',
+                   'x.y.z', 'xyz', '', False,
                    123, 456))
 
     def test_copy_run(self):
@@ -395,7 +393,7 @@ class TestObjects (unittest.TestCase):
         ''' Check behavior of objects.read_run()
         '''
         self.db.fetchone.return_value = (123, '', '', b'', None, {}, True, None,
-                                         __version__, '', None, None, '', False)
+                                         'x.y.z', '', None, None, '', False)
         
         run = read_run(self.db, 123)
         self.assertEqual(run.id, 123)
@@ -412,7 +410,7 @@ class TestObjects (unittest.TestCase):
         ''' Check behavior of objects.read_run()
         '''
         self.db.fetchone.return_value = (123, '', '', None, None, {}, True, None,
-                                         __version__, '', None, None, '', False)
+                                         'x.y.z', '', None, None, '', False)
         
         run = read_run(self.db, 123)
         self.assertEqual(run.id, 123)
@@ -1962,9 +1960,9 @@ class TestHook (unittest.TestCase):
             got_state2 = json.loads(runs[1].state.to_json())
             got_state3 = json.loads(runs[2].state.to_json())
             
-            self.assertEqual(runs[0].code_version, __version__)
-            self.assertEqual(runs[1].code_version, __version__)
-            self.assertEqual(runs[2].code_version, __version__)
+            self.assertEqual(runs[0].code_version, 'i')
+            self.assertEqual(runs[1].code_version, 'i')
+            self.assertEqual(runs[2].code_version, 'i')
         
             for key in ('source', 'cache', 'sample', 'geometry type', 'address count',
                         'version', 'fingerprint', 'cache time', 'processed', 'output',