From fb68982d07e2aaebb838bea6c5d86ff807de1e01 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 7 Jun 2017 23:07:48 +0300 Subject: [PATCH 01/11] build_linux: add "rpm" package for debian-based distros Without it, dvc.rpm is not generated when ./build_linux.sh is ran on debian-based distro. Signed-off-by: Ruslan Kuprieiev --- build_linux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_linux.sh b/build_linux.sh index 2a1d15aaa..eb72e6423 100755 --- a/build_linux.sh +++ b/build_linux.sh @@ -45,7 +45,7 @@ install_dependencies() elif command_exists yum; then sudo yum install ruby-devel gcc make rpm-build elif command_exists apt-get; then - sudo apt-get install ruby ruby-dev rubygems build-essential + sudo apt-get install ruby ruby-dev rubygems build-essential rpm else echo "Unable to install fpm dependencies" && exit 1 fi From 88692eb37c7caacd943f88b0e77dd738a8ac77ac Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 11 Jun 2017 21:20:05 +0300 Subject: [PATCH 02/11] travis: add code-climate hook Signed-off-by: Ruslan Kuprieiev --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 741cd7794..8bffee265 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,3 +9,5 @@ install: - pip install -r requirements.txt script: - ./unittests.sh +after_sucess: + - CODECLIMATE_REPO_TOKEN=b27257bacc4812c8e6d37285ba34559804e4a207bf6932723a1c9966e5807670 codeclimate-test-reporter From 31b25f7015ceee9a95b7feca374379e648e05833 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 11 Jun 2017 21:32:11 +0300 Subject: [PATCH 03/11] test: add coverage to test requirements Signed-off-by: Ruslan Kuprieiev --- test-requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 test-requirements.txt diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..4ebc8aea5 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +coverage From 577878c88754065b9cf81275ceaf318ed17301ca Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 11 Jun 2017 21:32:47 +0300 Subject: [PATCH 04/11] travis: use test-requirements.txt Signed-off-by: Ruslan Kuprieiev --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 8bffee265..06a722e1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ python: install: - pip install --upgrade pip - pip install -r requirements.txt + - pip install -r test-requirements.txt script: - ./unittests.sh after_sucess: From 0d3ef3c22fd8897e5e239c6b80acd4915683e8fa Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 11 Jun 2017 22:25:43 +0300 Subject: [PATCH 05/11] test: fix test_config Signed-off-by: Ruslan Kuprieiev --- tests/test_config.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index f586c5260..6a22db39b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -10,7 +10,8 @@ import mock from dvc.path.path import Path from dvc.system import System from dvc.config import Config -from dvc.command.data_cloud import DataCloud +from dvc.data_cloud import DataCloud +from dvc.settings import Settings class TestConfigTest(TestCase): def setUp(self): @@ -34,8 +35,8 @@ class TestConfigTest(TestCase): ) s = StringIO.StringIO('\n'.join(c)) conf = Config(s, conf_pseudo_file = s) - cloud = DataCloud(conf) - self.assertEqual(cloud.typ, 'aws') + cloud = DataCloud(Settings(None, None, conf)) + self.assertEqual(cloud.typ, 'AWS') self.assertEqual(cloud._cloud.storage_bucket, 'globalsb') self.assertEqual(cloud._cloud.storage_prefix, 'global_storage_path') @@ -53,8 +54,8 @@ class TestConfigTest(TestCase): ) s = StringIO.StringIO('\n'.join(c)) conf = Config(s, conf_pseudo_file=s) - cloud = DataCloud(conf) - self.assertEqual(cloud.typ, 'aws') + cloud = DataCloud(Settings(None, None, conf)) + self.assertEqual(cloud.typ, 'AWS') self.assertEqual(cloud._cloud.storage_bucket, 'awssb') self.assertEqual(cloud._cloud.storage_prefix, 'aws_storage_path') @@ -92,7 +93,7 @@ class TestConfigTest(TestCase): patcher = mock.patch('__builtin__.open', side_effect=self.mocked_open_aws_default_credentials) patcher.start() conf = Config(s, conf_pseudo_file=s) - cloud = DataCloud(conf) + cloud = DataCloud(Settings(None, None, conf)) aws_creds = cloud._cloud.get_aws_credentials() patcher.stop() @@ -123,7 +124,7 @@ class TestConfigTest(TestCase): patcher = mock.patch('__builtin__.open', side_effect=self.mocked_open_aws_default_credentials) patcher.start() conf = Config(s, conf_pseudo_file=s) - cloud = DataCloud(conf) + cloud = DataCloud(Settings(None, None, conf)) aws_creds = cloud._cloud.get_aws_credentials() patcher.stop() From 56b07a4ee3cf920612b44ab368f34d92049bb1cd Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 11 Jun 2017 22:26:23 +0300 Subject: [PATCH 06/11] debug: add assert Settings to DataCloud Signed-off-by: Ruslan Kuprieiev --- dvc/data_cloud.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dvc/data_cloud.py b/dvc/data_cloud.py index 7491c7f57..d98d961d4 100644 --- a/dvc/data_cloud.py +++ b/dvc/data_cloud.py @@ -13,6 +13,7 @@ from dvc.exceptions import DvcException from dvc.runtime import Runtime from dvc.system import System from dvc.config import ConfigError +from dvc.settings import Settings class DataCloudError(DvcException): def __init__(self, msg): @@ -333,6 +334,8 @@ class DataCloud(object): } def __init__(self, settings): + assert isinstance(settings, Settings) + #To handle ConfigI case if not hasattr(settings.config, '_config'): self._cloud = DataCloudBase(None, None, None) From 016229d1939deaee817a587cf01bde6d621a2e34 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 11 Jun 2017 22:28:43 +0300 Subject: [PATCH 07/11] travis: add dummy git user and mail Signed-off-by: Ruslan Kuprieiev --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 06a722e1e..dc0b0bfbb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ install: - pip install --upgrade pip - pip install -r requirements.txt - pip install -r test-requirements.txt + - git config --global user.email "dvctester@example.com" + - git config --global user.name "DVC Tester" script: - ./unittests.sh after_sucess: From b502691b0e1891f7584b174a86a632409b129bc5 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 11 Jun 2017 22:42:29 +0300 Subject: [PATCH 08/11] unittests: exit if nosetests exits with error code For now unitetests.sh is useless, as it returns 0 anyway. Signed-off-by: Ruslan Kuprieiev --- unittests.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/unittests.sh b/unittests.sh index 3dfef3760..04fcc94ba 100755 --- a/unittests.sh +++ b/unittests.sh @@ -1,3 +1,6 @@ +#!/bin/bash +set -e + nosetests --cover-inclusive --cover-erase --cover-package=dvc --with-coverage if [ "$1" = "report" ]; then From 8253f449ca8970067e6310837b533bf91d489299 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 11 Jun 2017 22:49:15 +0300 Subject: [PATCH 09/11] data_cloud: check if cloud section exists Signed-off-by: Ruslan Kuprieiev --- dvc/data_cloud.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dvc/data_cloud.py b/dvc/data_cloud.py index d98d961d4..f0752574c 100644 --- a/dvc/data_cloud.py +++ b/dvc/data_cloud.py @@ -348,6 +348,9 @@ class DataCloud(object): if self.typ not in self.CLOUD_MAP.keys(): raise ConfigError('Wrong cloud type %s specified' % self.typ) + if self.typ not in self._config.keys(): + raise ConfigError('Can\'t find cloud section \'[%s]\' in config' % self.typ) + self._cloud = self.CLOUD_MAP[self.typ](self._settings, self._config, self._config[self.typ]) self.sanity_check() From 52d4c001a992e7914f628efdb7aec11e52fb3da3 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 11 Jun 2017 23:10:04 +0300 Subject: [PATCH 10/11] travis: add dummy aws credentials to make unitests work Our tests assume that user has his default credentials at ~/.aws/credentials, but this is not the case with travis. Signed-off-by: Ruslan Kuprieiev --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index dc0b0bfbb..bc42e035e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ install: - pip install -r test-requirements.txt - git config --global user.email "dvctester@example.com" - git config --global user.name "DVC Tester" + - mkdir -p ~/.aws && printf "[default]\naws_access_key_id = ABCDEFG\naws_secret_access_key = 123456789" > ~/.aws/credentials script: - ./unittests.sh after_sucess: From 4078e902d1219eaecd9d077fa2bf38acb3df49d5 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 11 Jun 2017 23:23:20 +0300 Subject: [PATCH 11/11] test_config: python3 fix 1) use io for StringIO in python3 2) use builtins instead of __builtin__ 3) use StringIO instead of BytesIO when mocking aws config Othervise this test fails on python3. Signed-off-by: Ruslan Kuprieiev --- tests/test_config.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index 6a22db39b..43e1ae8e4 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,11 +1,22 @@ import io import os import shutil -import StringIO import traceback from unittest import TestCase import mock +try: + from StringIO import StringIO +except ImportError: + # Python 3 + from io import StringIO + +try: + import __builtin__ + builtin_module_name = '__builtin__' +except ImportError: + # Python 3 + builtin_module_name = 'builtins' from dvc.path.path import Path from dvc.system import System @@ -33,7 +44,7 @@ class TestConfigTest(TestCase): "[GCP]", "StoragePath = googlesb/google_storage_path" ) - s = StringIO.StringIO('\n'.join(c)) + s = StringIO('\n'.join(c)) conf = Config(s, conf_pseudo_file = s) cloud = DataCloud(Settings(None, None, conf)) self.assertEqual(cloud.typ, 'AWS') @@ -52,7 +63,7 @@ class TestConfigTest(TestCase): "[GCP]", "StoragePath = googlesb/google_storage_path" ) - s = StringIO.StringIO('\n'.join(c)) + s = StringIO('\n'.join(c)) conf = Config(s, conf_pseudo_file=s) cloud = DataCloud(Settings(None, None, conf)) self.assertEqual(cloud.typ, 'AWS') @@ -66,13 +77,13 @@ class TestConfigTest(TestCase): creds0 = ("[default]", "aws_access_key_id = default_access_id", "aws_secret_access_key = default_sekret") - return io.BytesIO('\n'.join(creds0)) + return StringIO('\n'.join(creds0)) creds1 = ("[default]", "aws_access_key_id = override_access_id", "aws_secret_access_key = override_sekret") - return io.BytesIO('\n'.join(creds1)) + return StringIO('\n'.join(creds1)) def aws_credentials_default_test(self): """ in absence of [AWS] -> CredentialPath, aws creds should be read from ~/.aws/credentials """ @@ -88,9 +99,10 @@ class TestConfigTest(TestCase): "StoragePath = awssb/aws_storage_path", "CredentialPath =", ) - s = StringIO.StringIO('\n'.join(c)) + s = StringIO('\n'.join(c)) + + patcher = mock.patch(builtin_module_name + '.open', side_effect=self.mocked_open_aws_default_credentials) - patcher = mock.patch('__builtin__.open', side_effect=self.mocked_open_aws_default_credentials) patcher.start() conf = Config(s, conf_pseudo_file=s) cloud = DataCloud(Settings(None, None, conf)) @@ -119,9 +131,10 @@ class TestConfigTest(TestCase): "StoragePath = awssb/aws_storage_path", "CredentialPath = some_credential_path", ) - s = StringIO.StringIO('\n'.join(c)) + s = StringIO('\n'.join(c)) + + patcher = mock.patch(builtin_module_name + '.open', side_effect=self.mocked_open_aws_default_credentials) - patcher = mock.patch('__builtin__.open', side_effect=self.mocked_open_aws_default_credentials) patcher.start() conf = Config(s, conf_pseudo_file=s) cloud = DataCloud(Settings(None, None, conf))