Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions compatibility_lib/compatibility_lib/compatibility_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ def save_compatibility_statuses(
for cs in compatibility_statuses:
if len(cs.packages) == 1:
install_name = cs.packages[0].install_name
# Only store the dep info for latest version of the package
# being checked. e.g. pip install apache-beam will have
# different version installed in py2/3.
if not self._should_update_dep_info(
cs, release_time_rows.get(install_name)):
continue
row = self._compatibility_status_to_release_time_row(cs)
if row:
release_time_rows[install_name] = row
Expand All @@ -416,6 +422,25 @@ def save_compatibility_statuses(
self._release_time_table,
row)

def _should_update_dep_info(self, cs, dep_info_stored):
"""Return True if the stored version is behind latest version."""
if dep_info_stored is None:
return True

install_name = cs.packages[0].install_name
install_name_sanitized = install_name.split('[')[0]
installed_version = cs.dependency_info[
install_name_sanitized]['installed_version']

installed_version_stored = '0'
for row in dep_info_stored:
if row['install_name'] == install_name \
and row['dep_name'] == install_name_sanitized:
installed_version_stored = row['installed_version']
break

return True if installed_version > installed_version_stored else False

@retrying.retry(stop_max_attempt_number=7,
wait_fixed=2000)
def get_dependency_info(self, package_name):
Expand Down
61 changes: 60 additions & 1 deletion compatibility_lib/compatibility_lib/test_compatibility_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
PACKAGE_1 = package.Package("package1")
PACKAGE_2 = package.Package("package2")
PACKAGE_3 = package.Package("package3")
PACKAGE_4 = package.Package("package4")
PACKAGE_4 = package.Package("package4[gcp]")


class TestCompatibilityResult(unittest.TestCase):
Expand Down Expand Up @@ -414,6 +414,65 @@ def MockClient(project=None):
mock_client.insert_rows.assert_called_with(
store._release_time_table, [row_release_time])

def test_save_compatibility_statuses_release_time_for_latest(self):
mock_client = mock.Mock()
packages = [PACKAGE_4]
timestamp = '2018-07-17 03:01:06.11693 UTC'
status = compatibility_store.Status.SUCCESS
comp_status_py2 = mock.Mock(
packages=packages,
python_major_version='2',
status=status,
details=None,
dependency_info={'package4': {
'installed_version': '2.7.0',
'installed_version_time': '2018-05-12T16:26:31',
'latest_version': '2.7.0',
'current_time': '2018-07-13T17:11:29.140608',
'latest_version_time': '2018-05-12T16:26:31',
'is_latest': True,
}},
timestamp=timestamp)
comp_status_py3 = mock.Mock(
packages=packages,
python_major_version='3',
status=status,
details=None,
dependency_info={'package4': {
'installed_version': '2.2.0',
'installed_version_time': '2018-05-12T16:26:31',
'latest_version': '2.7.0',
'current_time': '2018-07-13T17:11:29.140608',
'latest_version_time': '2018-05-12T16:26:31',
'is_latest': False,
}},
timestamp=timestamp)
row_release_time = {
'install_name': 'package4[gcp]',
'dep_name': 'package4',
'installed_version': '2.7.0',
'installed_version_time': '2018-05-12T16:26:31',
'latest_version': '2.7.0',
'timestamp': '2018-07-13T17:11:29.140608',
'latest_version_time': '2018-05-12T16:26:31',
'is_latest': True,
}

def MockClient(project=None):
return mock_client

patch_client = mock.patch(
'compatibility_lib.compatibility_store.bigquery.Client',
MockClient)

with patch_client:
store = compatibility_store.CompatibilityStore()
store.save_compatibility_statuses(
[comp_status_py2, comp_status_py3])

mock_client.insert_rows.assert_called_with(
store._release_time_table, [row_release_time])


class MockClient(object):

Expand Down