summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource/test_smartos.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2016-05-11 16:47:50 -0700
committerJoshua Harlow <harlowja@gmail.com>2016-05-11 16:47:50 -0700
commit12d7ee2cb6589b866ab26b508b15c65326481d6c (patch)
tree397fb383c718d52929f70fc54402f865187120a4 /tests/unittests/test_datasource/test_smartos.py
parente885f694c9951101b57ee182bebc000e398da563 (diff)
downloadvyos-cloud-init-12d7ee2cb6589b866ab26b508b15c65326481d6c.tar.gz
vyos-cloud-init-12d7ee2cb6589b866ab26b508b15c65326481d6c.zip
Use a fake serial module that will allow tests to contine
Instead of aborting all serial using tests instead just create a serial module in cloudinit that will create a fake and broken serial class when pyserial is not actually installed. This allows for using the datasource and tests that exist in a more functional and tested manner (even when pyserial is not found).
Diffstat (limited to 'tests/unittests/test_datasource/test_smartos.py')
-rw-r--r--tests/unittests/test_datasource/test_smartos.py15
1 files changed, 4 insertions, 11 deletions
diff --git a/tests/unittests/test_datasource/test_smartos.py b/tests/unittests/test_datasource/test_smartos.py
index 6b628276..f536ef4f 100644
--- a/tests/unittests/test_datasource/test_smartos.py
+++ b/tests/unittests/test_datasource/test_smartos.py
@@ -33,13 +33,8 @@ import tempfile
import uuid
from binascii import crc32
-try:
- # Serial does not work on py2.6 (anymore)
- import serial
- from cloudinit.sources import DataSourceSmartOS
- WILL_WORK = True
-except ImportError:
- WILL_WORK = False
+from cloudinit import serial
+from cloudinit.sources import DataSourceSmartOS
import six
@@ -81,8 +76,7 @@ def get_mock_client(mockdata):
class TestSmartOSDataSource(helpers.FilesystemMockingTestCase):
def setUp(self):
super(TestSmartOSDataSource, self).setUp()
- if not WILL_WORK:
- raise SkipTest("This test will not work")
+
self.tmp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.tmp)
self.legacy_user_d = tempfile.mkdtemp()
@@ -448,8 +442,7 @@ class TestJoyentMetadataClient(helpers.FilesystemMockingTestCase):
def setUp(self):
super(TestJoyentMetadataClient, self).setUp()
- if not WILL_WORK:
- raise SkipTest("This test will not work")
+
self.serial = mock.MagicMock(spec=serial.Serial)
self.request_id = 0xabcdef12
self.metadata_value = 'value'