summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Milner <mike.milner@canonical.com>2012-02-21 15:35:04 -0400
committerMike Milner <mike.milner@canonical.com>2012-02-21 15:35:04 -0400
commite8a3e39c1a6356460418d45f5b24f29b3fe6f20b (patch)
treeb130a9c820cacbde337b21879659765cb16cf7f0 /tests
parent8b17caade46cf84050961e24a0006386dbe96669 (diff)
downloadvyos-cloud-init-e8a3e39c1a6356460418d45f5b24f29b3fe6f20b.tar.gz
vyos-cloud-init-e8a3e39c1a6356460418d45f5b24f29b3fe6f20b.zip
Lint fixes.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test__init__.py95
1 files changed, 60 insertions, 35 deletions
diff --git a/tests/unittests/test__init__.py b/tests/unittests/test__init__.py
index f1818e9c..d273748a 100644
--- a/tests/unittests/test__init__.py
+++ b/tests/unittests/test__init__.py
@@ -1,12 +1,8 @@
-from unittest import TestCase
from mocker import MockerTestCase, ANY, ARGS, KWARGS
-from tempfile import mkdtemp
-from shutil import rmtree
import os
-import stat
-import sys
-from cloudinit import partwalker_handle_handler, handler_handle_part, handler_register
+from cloudinit import (partwalker_handle_handler, handler_handle_part,
+ handler_register)
from cloudinit.util import write_file, logexc
@@ -19,9 +15,11 @@ class TestPartwalkerHandleHandler(MockerTestCase):
"handlers": [],
"data": None}
- self.expected_module_name = "part-handler-%03d" % self.data["handlercount"]
+ self.expected_module_name = "part-handler-%03d" % (
+ self.data["handlercount"],)
expected_file_name = "%s.py" % self.expected_module_name
- expected_file_fullname = os.path.join(self.data["handlerdir"], expected_file_name)
+ expected_file_fullname = os.path.join(self.data["handlerdir"],
+ expected_file_name)
self.module_fake = "fake module handle"
self.ctype = None
self.filename = None
@@ -38,12 +36,15 @@ class TestPartwalkerHandleHandler(MockerTestCase):
import_mock(self.expected_module_name)
self.mocker.result(self.module_fake)
# Mock the handle_register function
- handle_reg_mock = self.mocker.replace(handler_register, passthrough=False)
- handle_reg_mock(self.module_fake, self.data["handlers"], self.data["data"], self.data["frequency"])
+ handle_reg_mock = self.mocker.replace(handler_register,
+ passthrough=False)
+ handle_reg_mock(self.module_fake, self.data["handlers"],
+ self.data["data"], self.data["frequency"])
# Activate mocks
self.mocker.replay()
- partwalker_handle_handler(self.data, self.ctype, self.filename, self.payload)
+ partwalker_handle_handler(self.data, self.ctype, self.filename,
+ self.payload)
self.assertEqual(1, self.data["handlercount"])
@@ -57,12 +58,14 @@ class TestPartwalkerHandleHandler(MockerTestCase):
logexc_mock = self.mocker.replace(logexc, passthrough=False)
logexc_mock(ANY)
# Mock the print_exc function
- print_exc_mock = self.mocker.replace("traceback.print_exc", passthrough=False)
+ print_exc_mock = self.mocker.replace("traceback.print_exc",
+ passthrough=False)
print_exc_mock(ARGS, KWARGS)
# Activate mocks
self.mocker.replay()
- partwalker_handle_handler(self.data, self.ctype, self.filename, self.payload)
+ partwalker_handle_handler(self.data, self.ctype, self.filename,
+ self.payload)
def test_attribute_error(self):
"""Payload gets written to file and added to C{pdata}."""
@@ -71,19 +74,23 @@ class TestPartwalkerHandleHandler(MockerTestCase):
import_mock(self.expected_module_name)
self.mocker.result(self.module_fake)
# Mock the handle_register function
- handle_reg_mock = self.mocker.replace(handler_register, passthrough=False)
- handle_reg_mock(self.module_fake, self.data["handlers"], self.data["data"], self.data["frequency"])
+ handle_reg_mock = self.mocker.replace(handler_register,
+ passthrough=False)
+ handle_reg_mock(self.module_fake, self.data["handlers"],
+ self.data["data"], self.data["frequency"])
self.mocker.throw(AttributeError())
# Mock log function
logexc_mock = self.mocker.replace(logexc, passthrough=False)
logexc_mock(ANY)
# Mock the print_exc function
- print_exc_mock = self.mocker.replace("traceback.print_exc", passthrough=False)
+ print_exc_mock = self.mocker.replace("traceback.print_exc",
+ passthrough=False)
print_exc_mock(ARGS, KWARGS)
# Activate mocks
self.mocker.replay()
- partwalker_handle_handler(self.data, self.ctype, self.filename, self.payload)
+ partwalker_handle_handler(self.data, self.ctype, self.filename,
+ self.payload)
class TestHandlerHandlePart(MockerTestCase):
@@ -95,33 +102,45 @@ class TestHandlerHandlePart(MockerTestCase):
self.frequency = "once-per-instance"
def test_normal_version_1(self):
- """C{handle_part} is called without frequency for C{handler_version} == 1"""
+ """
+ C{handle_part} is called without C{frequency} for
+ C{handler_version} == 1.
+ """
# Build a mock part-handler module
mod_mock = self.mocker.mock()
getattr(mod_mock, "frequency")
self.mocker.result("once-per-instance")
getattr(mod_mock, "handler_version")
self.mocker.result(1)
- mod_mock.handle_part(self.data, self.ctype, self.filename, self.payload)
+ mod_mock.handle_part(self.data, self.ctype, self.filename,
+ self.payload)
self.mocker.replay()
-
- handler_handle_part(mod_mock, self.data, self.ctype, self.filename, self.payload, self.frequency)
+
+ handler_handle_part(mod_mock, self.data, self.ctype, self.filename,
+ self.payload, self.frequency)
def test_normal_version_2(self):
- """C{handle_part} is called with frequency for C{handler_version} == 2"""
+ """
+ C{handle_part} is called with C{frequency} for
+ C{handler_version} == 2.
+ """
# Build a mock part-handler module
mod_mock = self.mocker.mock()
getattr(mod_mock, "frequency")
self.mocker.result("once-per-instance")
getattr(mod_mock, "handler_version")
self.mocker.result(2)
- mod_mock.handle_part(self.data, self.ctype, self.filename, self.payload, self.frequency)
+ mod_mock.handle_part(self.data, self.ctype, self.filename,
+ self.payload, self.frequency)
self.mocker.replay()
-
- handler_handle_part(mod_mock, self.data, self.ctype, self.filename, self.payload, self.frequency)
+
+ handler_handle_part(mod_mock, self.data, self.ctype, self.filename,
+ self.payload, self.frequency)
def test_modfreq_per_always(self):
- """C{handle_part} is called regardless of frequency if nofreq is always."""
+ """
+ C{handle_part} is called regardless of frequency if nofreq is always.
+ """
self.frequency = "once"
# Build a mock part-handler module
mod_mock = self.mocker.mock()
@@ -129,10 +148,12 @@ class TestHandlerHandlePart(MockerTestCase):
self.mocker.result("always")
getattr(mod_mock, "handler_version")
self.mocker.result(2)
- mod_mock.handle_part(self.data, self.ctype, self.filename, self.payload, self.frequency)
+ mod_mock.handle_part(self.data, self.ctype, self.filename,
+ self.payload, self.frequency)
self.mocker.replay()
-
- handler_handle_part(mod_mock, self.data, self.ctype, self.filename, self.payload, self.frequency)
+
+ handler_handle_part(mod_mock, self.data, self.ctype, self.filename,
+ self.payload, self.frequency)
def test_no_handle_when_modfreq_once(self):
"""C{handle_part} is not called if frequency is once"""
@@ -142,8 +163,9 @@ class TestHandlerHandlePart(MockerTestCase):
getattr(mod_mock, "frequency")
self.mocker.result("once-per-instance")
self.mocker.replay()
-
- handler_handle_part(mod_mock, self.data, self.ctype, self.filename, self.payload, self.frequency)
+
+ handler_handle_part(mod_mock, self.data, self.ctype, self.filename,
+ self.payload, self.frequency)
def test_exception_is_caught(self):
"""Exceptions within C{handle_part} are caught and logged."""
@@ -153,14 +175,17 @@ class TestHandlerHandlePart(MockerTestCase):
self.mocker.result("once-per-instance")
getattr(mod_mock, "handler_version")
self.mocker.result(1)
- mod_mock.handle_part(self.data, self.ctype, self.filename, self.payload)
+ mod_mock.handle_part(self.data, self.ctype, self.filename,
+ self.payload)
self.mocker.throw(Exception())
# Mock log function
logexc_mock = self.mocker.replace(logexc, passthrough=False)
logexc_mock(ANY)
# Mock the print_exc function
- print_exc_mock = self.mocker.replace("traceback.print_exc", passthrough=False)
+ print_exc_mock = self.mocker.replace("traceback.print_exc",
+ passthrough=False)
print_exc_mock(ARGS, KWARGS)
self.mocker.replay()
-
- handler_handle_part(mod_mock, self.data, self.ctype, self.filename, self.payload, self.frequency)
+
+ handler_handle_part(mod_mock, self.data, self.ctype, self.filename,
+ self.payload, self.frequency)