From a5eda0d3054f3c1213cf468832b7bd3780b513d8 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 15 Mar 2015 10:14:16 -0700 Subject: [PATCH] Fixing Python 3 test incompatibility with builtins. --- atticmatic/attic.py | 2 +- atticmatic/tests/unit/test_attic.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/atticmatic/attic.py b/atticmatic/attic.py index f0c9e7e..d0b1cc8 100644 --- a/atticmatic/attic.py +++ b/atticmatic/attic.py @@ -28,7 +28,7 @@ def create_archive(excludes_filename, verbose, source_directories, repository): try: subprocess.check_output(command, stderr=subprocess.STDOUT) - except subprocess.CalledProcessError, error: + except subprocess.CalledProcessError as error: print(error.output.strip(), file=sys.stderr) if re.search('Error: Repository .* does not exist', error.output): diff --git a/atticmatic/tests/unit/test_attic.py b/atticmatic/tests/unit/test_attic.py index 30431cc..e54f445 100644 --- a/atticmatic/tests/unit/test_attic.py +++ b/atticmatic/tests/unit/test_attic.py @@ -1,5 +1,10 @@ from collections import OrderedDict -import sys +try: + # Python 2 + import __builtin__ as builtins +except ImportError: + # Python 3 + import builtins from flexmock import flexmock from nose.tools import assert_raises @@ -23,7 +28,7 @@ def insert_subprocess_check_output_mock(call_command, error_output=None, **kwarg if error_output: expectation.and_raise(MockCalledProcessError, output=error_output) - flexmock(sys.modules['__builtin__']).should_receive('print') + flexmock(builtins).should_receive('print') flexmock(module).subprocess = subprocess return subprocess