Skip to content

Commit 53da27c

Browse files
committed
Update to support python3.
1 parent 8c4f17b commit 53da27c

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: python
22
python:
33
- "2.7"
4+
- "3.4"
45

56
install:
67
- pip install tox
@@ -10,5 +11,6 @@ script:
1011

1112
env:
1213
- TOXENV=py27
14+
- TOXENV=py34
1315
- TOXENV=pep8
1416
- TOXENV=coveralls

caso/exception.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import sys
1818

19+
import six
20+
1921
from caso import log
2022

2123
LOG = log.getLogger(__name__)
@@ -37,7 +39,7 @@ def __init__(self, message=None, **kwargs):
3739
LOG.exception('Exception in string format operation')
3840
for name, value in kwargs.iteritems():
3941
LOG.error("%s: %s" % (name, value))
40-
raise exc_info[0], exc_info[1], exc_info[2]
42+
six.reraise(exc_info[0], exc_info[1], exc_info[2])
4143

4244
super(CasoException, self).__init__(message)
4345

caso/tests/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import fixtures
2121
from oslo.config import cfg
22+
import six
2223
import testtools
2324

2425
CONF = cfg.CONF
@@ -58,5 +59,5 @@ def setUp(self):
5859
def flags(self, **kw):
5960
"""Override flag variables for a test."""
6061
group = kw.pop('group', None)
61-
for k, v in kw.iteritems():
62+
for k, v in six.iteritems(kw):
6263
CONF.set_override(k, v, group)

caso/tests/test_manager.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
Tests for `caso.manager` module.
1717
"""
1818

19-
import contextlib
2019
import datetime
2120

2221
from dateutil import tz
@@ -36,7 +35,7 @@ def setUp(self):
3635
"messenger": mock.patch('caso.messenger.Manager'),
3736
}
3837
self.mocks = {}
39-
for k, p in self.patchers.iteritems():
38+
for k, p in six.iteritems(self.patchers):
4039
self.mocks[k] = p.start()
4140

4241
self.manager = manager.Manager()
@@ -54,17 +53,20 @@ def test_lastrun_does_not_exist(self):
5453

5554
def test_lastrun_exists(self):
5655
expected = datetime.datetime(2014, 12, 10, 13, 10, 26, 664598)
57-
aux = six.StringIO(expected)
56+
aux = six.StringIO(str(expected))
5857

59-
with contextlib.nested(
60-
mock.patch("os.path.exists"),
61-
mock.patch('__builtin__.open')
62-
) as (path, fopen):
63-
fopen.return_value.__enter__ = lambda x: aux
64-
fopen.return_value.__exit__ = mock.Mock()
65-
path.return_value = True
58+
if six.PY3:
59+
builtins_open = 'builtins.open'
60+
else:
61+
builtins_open = '__builtin__.open'
6662

67-
self.assertEqual(expected, self.manager.lastrun)
63+
with mock.patch("os.path.exists") as path:
64+
with mock.patch(builtins_open) as fopen:
65+
fopen.return_value.__enter__ = lambda x: aux
66+
fopen.return_value.__exit__ = mock.Mock()
67+
path.return_value = True
68+
69+
self.assertEqual(expected, self.manager.lastrun)
6870

6971
def test_lastrun_is_invalid(self):
7072
aux = six.StringIO("foo")
@@ -74,15 +76,18 @@ def test_lastrun_is_invalid(self):
7476
def call(self):
7577
return self.manager.lastrun
7678

77-
with contextlib.nested(
78-
mock.patch("os.path.exists"),
79-
mock.patch('__builtin__.open')
80-
) as (path, fopen):
81-
fopen.return_value.__enter__ = lambda x: aux
82-
fopen.return_value.__exit__ = mock.Mock()
83-
path.return_value = True
79+
if six.PY3:
80+
builtins_open = 'builtins.open'
81+
else:
82+
builtins_open = '__builtin__.open'
83+
84+
with mock.patch("os.path.exists") as path:
85+
with mock.patch(builtins_open) as fopen:
86+
fopen.return_value.__enter__ = lambda x: aux
87+
fopen.return_value.__exit__ = mock.Mock()
88+
path.return_value = True
8489

85-
self.assertRaises(ValueError, call, self)
90+
self.assertRaises(ValueError, call, self)
8691

8792
def test_dry_run(self):
8893
self.flags(dry_run=True)

0 commit comments

Comments
 (0)