| |
@@ -5,14 +5,21 @@
|
| |
|
| |
'''Unit tests for libtaskotron/config.py'''
|
| |
|
| |
+ from __future__ import print_function
|
| |
import os
|
| |
+ import sys
|
| |
import pytest
|
| |
import mock
|
| |
- from StringIO import StringIO
|
| |
+ from io import StringIO
|
| |
+
|
| |
from libtaskotron import config
|
| |
from libtaskotron import exceptions as exc
|
| |
|
| |
|
| |
+ PYVER = sys.version_info.major
|
| |
+ builtin_open = '__builtin__.open' if PYVER < 3 else 'builtins.open'
|
| |
+
|
| |
+
|
| |
@pytest.mark.usefixtures('setup')
|
| |
class TestConfig(object):
|
| |
|
| |
@@ -39,7 +46,7 @@
|
| |
'''By default we should have a testing profile'''
|
| |
assert os.getenv(config.PROFILE_VAR) == config.ProfileName.TESTING
|
| |
conf = config.get_config()
|
| |
- print conf
|
| |
+ print(conf)
|
| |
assert conf.profile == config.ProfileName.TESTING
|
| |
assert isinstance(conf, config.TestingConfig)
|
| |
|
| |
@@ -54,7 +61,7 @@
|
| |
def test_load_defaults(self):
|
| |
'''Test _load_defaults() function'''
|
| |
for attr, value in vars(config.ProfileName).items():
|
| |
- print attr, value
|
| |
+ print(attr, value)
|
| |
if attr.startswith('_'):
|
| |
continue
|
| |
conf = config._load_defaults(value)
|
| |
@@ -67,13 +74,13 @@
|
| |
|
| |
def test_load_file_empty(self):
|
| |
'''Test _load_file() function with empty file'''
|
| |
- contents = StringIO('')
|
| |
+ contents = StringIO(u'')
|
| |
conf_object = config._load_file(contents)
|
| |
assert conf_object == {}
|
| |
|
| |
def test_load_file_commented(self):
|
| |
'''Test _load_file() function with fully commented out file'''
|
| |
- contents = StringIO('''
|
| |
+ contents = StringIO(u'''
|
| |
# first commented line
|
| |
# second: line
|
| |
# last line
|
| |
@@ -83,7 +90,7 @@
|
| |
|
| |
def test_load_file_options(self):
|
| |
'''Test _load_file() function with some options present'''
|
| |
- contents = StringIO('''# a header comment
|
| |
+ contents = StringIO(u'''# a header comment
|
| |
option1: value1
|
| |
# option2: value2
|
| |
option3: 15
|
| |
@@ -98,22 +105,22 @@
|
| |
def test_load_file_invalid_syntax(self):
|
| |
'''Test _load_file() function with invalid syntax'''
|
| |
with pytest.raises(exc.TaskotronConfigError):
|
| |
- contents = StringIO('a single string (not dict)')
|
| |
+ contents = StringIO(u'a single string (not dict)')
|
| |
config._load_file(contents)
|
| |
|
| |
with pytest.raises(exc.TaskotronConfigError):
|
| |
- contents = StringIO('tab:\t #this is invalid in YAML')
|
| |
+ contents = StringIO(u'tab:\t #this is invalid in YAML')
|
| |
config._load_file(contents)
|
| |
|
| |
def test_load_file_invalid_type(self):
|
| |
'''Test _load_file() function with invalid option type'''
|
| |
# tmpdir is string, with string it should pass
|
| |
- contents = StringIO('tmpdir: foo')
|
| |
+ contents = StringIO(u'tmpdir: foo')
|
| |
config._load_file(contents)
|
| |
|
| |
# but with anything else, it should fail
|
| |
with pytest.raises(exc.TaskotronConfigError):
|
| |
- contents = StringIO('tmpdir: False')
|
| |
+ contents = StringIO(u'tmpdir: False')
|
| |
config._load_file(contents)
|
| |
|
| |
def test_merge_config(self):
|
| |
@@ -174,7 +181,7 @@
|
| |
file_data = '%'
|
| |
mocked_open = mock.mock_open(read_data=file_data)
|
| |
|
| |
- with mock.patch('__builtin__.open', mocked_open):
|
| |
+ with mock.patch(builtin_open, mocked_open):
|
| |
with pytest.raises(exc.TaskotronConfigError):
|
| |
config.parse_yaml_from_file('mocked_filename')
|
| |
|
| |
@@ -182,7 +189,7 @@
|
| |
file_data = ':'
|
| |
mocked_open = mock.mock_open(read_data=file_data)
|
| |
|
| |
- with mock.patch('__builtin__.open', mocked_open):
|
| |
+ with mock.patch(builtin_open, mocked_open):
|
| |
with pytest.raises(exc.TaskotronConfigError):
|
| |
config.parse_yaml_from_file('mocked_filename')
|
| |
|
| |
I am able to run the tests with:
tox -v -e py36 -- -v
There is one test that fail on me:
test_run_playbook_simple
fails on Python 2 and Python 3 consistently, I don't know what's wrong