datary
Advanced tools
| Metadata-Version: 1.1 | ||
| Name: datary | ||
| Version: 0.1.30 | ||
| Version: 0.1.31 | ||
| Summary: Datary Python sdk lib | ||
@@ -10,3 +10,2 @@ Home-page: https://github.com/Datary/python-sdk | ||
| Download-URL: https://github.com/Datary/python-sdk | ||
| Description-Content-Type: UNKNOWN | ||
| Description: UNKNOWN | ||
@@ -13,0 +12,0 @@ Keywords: datary,sdk,api |
@@ -138,4 +138,29 @@ | ||
| @classmethod | ||
| def make_index(cls, lista): | ||
| def make_index(cls, data): | ||
| """ | ||
| Transforms commit list into an index passing a list of dict or list | ||
| of lists. | ||
| ================ =================== =============================== | ||
| Parameter Type Description | ||
| ================ =================== =============================== | ||
| data list of lists/dicts list of commits | ||
| ================ =================== =============================== | ||
| """ | ||
| result = {} | ||
| # make index with list of dict data | ||
| if data and isinstance(data, list) and isinstance(data[0], dict): | ||
| result = cls._make_index_dict(data) | ||
| # make index with list of list data | ||
| elif data and isinstance(data, list) and isinstance(data[0], list): | ||
| result = cls._make_index_list(data) | ||
| return result | ||
| @classmethod | ||
| def _make_index_list(cls, list_of_lists): | ||
| """ | ||
| Transforms commit list into an index using path + basename as key | ||
@@ -147,3 +172,3 @@ and sha1 as value. | ||
| ================ ============= ==================================== | ||
| lista list list of commits | ||
| list_of_lists list of list list of commits | ||
| ================ ============= ==================================== | ||
@@ -153,9 +178,48 @@ | ||
| result = {} | ||
| for path, basename, data, sha1 in lista: | ||
| result[os.path.join(path, basename)] = {'path': path, | ||
| 'basename': basename, | ||
| 'data': data, | ||
| 'sha1': sha1} | ||
| try: | ||
| for path, basename, data, sha1 in iter(list_of_lists): | ||
| result[os.path.join(path, basename)] = {'path': path, | ||
| 'basename': basename, | ||
| 'data': data, | ||
| 'sha1': sha1} | ||
| except Exception as ex: | ||
| msg = 'Fail to make row to index at make_index_list - {}' | ||
| logger.error(msg.format(ex)) | ||
| return result | ||
| @classmethod | ||
| def _make_index_dict(cls, list_of_dicts): | ||
| """ | ||
| Transforms commit dict into an index using path + basename as key | ||
| and sha1 as value. | ||
| ================ ============= ==================================== | ||
| Parameter Type Description | ||
| ================ ============= ==================================== | ||
| list_of_dicts list of dict list of commits | ||
| ================ ============= ==================================== | ||
| """ | ||
| result = {} | ||
| for dict_commit in iter(list_of_dicts): | ||
| try: | ||
| key = os.path.join( | ||
| dict_commit.get('path'), | ||
| dict_commit.get('basename')) | ||
| result[key] = { | ||
| 'path': dict_commit.get('path'), | ||
| 'basename': dict_commit.get('basename'), | ||
| 'data': dict_commit.get('data'), | ||
| 'sha1': dict_commit.get('sha1') | ||
| } | ||
| except Exception as ex: | ||
| msg = 'Fail to make row to index at make_index_dict - {}' | ||
| logger.error(msg.format(ex)) | ||
| return result | ||
| def compare_commits(self, last_commit, actual_commit, | ||
@@ -162,0 +226,0 @@ strict=True, **kwargs): |
@@ -84,14 +84,81 @@ # -*- coding: utf-8 -*- | ||
| def test_make_index(self): | ||
| @mock.patch('datary.commits.DataryCommits._make_index_dict') | ||
| @mock.patch('datary.commits.DataryCommits._make_index_list') | ||
| def test_make_index(self, mock_index_list, mock_index_dict): | ||
| """ | ||
| Test Datary make_index | ||
| """ | ||
| lista = self.commit_test1 | ||
| result = self.datary.make_index(lista) | ||
| test_index1 = [ | ||
| ['a', 1, 2, 3], | ||
| ['b', 1, 2, 3], | ||
| ['c', 1, 2, 3]] | ||
| test_index2 = [{'a': 1}, {'b': 2}, {'c': 3}] | ||
| # call with list of list | ||
| self.datary.make_index(test_index1) | ||
| self.assertEqual(mock_index_list.call_count, 1) | ||
| self.assertEqual(mock_index_dict.call_count, 0) | ||
| # call with list of dict | ||
| self.datary.make_index(test_index2) | ||
| self.assertEqual(mock_index_list.call_count, 1) | ||
| self.assertEqual(mock_index_dict.call_count, 1) | ||
| # call with empty | ||
| self.datary.make_index([]) | ||
| self.assertEqual(mock_index_list.call_count, 1) | ||
| self.assertEqual(mock_index_dict.call_count, 1) | ||
| def test_make_index_dict(self): | ||
| lista = [ | ||
| {'bad_test': 1}, | ||
| { | ||
| 'path': 'test_path1', | ||
| 'basename': 'test_basename1', | ||
| 'data': {}, | ||
| 'sha1': 'aa_sha1' | ||
| }, | ||
| { | ||
| 'path': 'test_path2', | ||
| 'basename': 'test_basename2', | ||
| 'data': {}, | ||
| 'sha1': 'caa_sha1' | ||
| }, | ||
| { | ||
| 'path': 'test_path3', | ||
| 'basename': 'test_basename3', | ||
| 'data': {}, | ||
| 'sha1': 'bb_sha1' | ||
| }, | ||
| { | ||
| 'path': 'test_path1', | ||
| 'basename': 'test_basename1', | ||
| 'data': {}, | ||
| 'sha1': 'dd_sha1' | ||
| }, | ||
| ] | ||
| result = self.datary._make_index_dict(lista) | ||
| expected_values = ['aa_sha1', 'caa_sha1', 'bb_sha1', 'dd_sha1'] | ||
| self.assertTrue(isinstance(result, dict)) | ||
| for element in result.values(): | ||
| self.assertTrue(element.get('sha1') in expected_values) | ||
| def test_make_index_list(self): | ||
| lista = self.commit_test1 + ['a'] | ||
| result = self.datary._make_index_list(lista) | ||
| expected_values = ['aa_sha1', 'caa_sha1', 'bb_sha1', 'dd_sha1'] | ||
| self.assertTrue(isinstance(result, dict)) | ||
| for element in result.values(): | ||
| self.assertTrue(element.get('sha1') in expected_values) | ||
| def test_compare_commits(self): | ||
@@ -98,0 +165,0 @@ """ |
@@ -5,2 +5,2 @@ #!/usr/bin/env python | ||
| """ | ||
| __version__ = "0.1.30" | ||
| __version__ = "0.1.31" |
+1
-2
| Metadata-Version: 1.1 | ||
| Name: datary | ||
| Version: 0.1.30 | ||
| Version: 0.1.31 | ||
| Summary: Datary Python sdk lib | ||
@@ -10,3 +10,2 @@ Home-page: https://github.com/Datary/python-sdk | ||
| Download-URL: https://github.com/Datary/python-sdk | ||
| Description-Content-Type: UNKNOWN | ||
| Description: UNKNOWN | ||
@@ -13,0 +12,0 @@ Keywords: datary,sdk,api |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
150391
2.93%3450
3.08%