summaryrefslogtreecommitdiff
path: root/tests/unittests/test_util.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests/test_util.py')
-rw-r--r--tests/unittests/test_util.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 38ab0c96..35e92445 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -1,12 +1,10 @@
-# pylint: disable=C0301
-# the mountinfo data lines are too long
import os
import stat
import yaml
from mocker import MockerTestCase
-from tests.unittests import helpers
-from unittest import TestCase
+from . import helpers
+import unittest
from cloudinit import importer
from cloudinit import util
@@ -18,7 +16,7 @@ class FakeSelinux(object):
self.match_what = match_what
self.restored = []
- def matchpathcon(self, path, mode): # pylint: disable=W0613
+ def matchpathcon(self, path, mode):
if path == self.match_what:
return
else:
@@ -27,11 +25,11 @@ class FakeSelinux(object):
def is_selinux_enabled(self):
return True
- def restorecon(self, path, recursive): # pylint: disable=W0613
+ def restorecon(self, path, recursive):
self.restored.append(path)
-class TestGetCfgOptionListOrStr(TestCase):
+class TestGetCfgOptionListOrStr(unittest.TestCase):
def test_not_found_no_default(self):
"""None is returned if key is not found and no default given."""
config = {}
@@ -124,16 +122,21 @@ class TestWriteFile(MockerTestCase):
def test_restorecon_if_possible_is_called(self):
"""Make sure the selinux guard is called correctly."""
+ my_file = os.path.join(self.tmp, "my_file")
+ with open(my_file, "w") as fp:
+ fp.write("My Content")
+
import_mock = self.mocker.replace(importer.import_module,
passthrough=False)
import_mock('selinux')
- fake_se = FakeSelinux('/etc/hosts')
+
+ fake_se = FakeSelinux(my_file)
self.mocker.result(fake_se)
self.mocker.replay()
- with util.SeLinuxGuard("/etc/hosts") as is_on:
+ with util.SeLinuxGuard(my_file) as is_on:
self.assertTrue(is_on)
self.assertEqual(1, len(fake_se.restored))
- self.assertEqual('/etc/hosts', fake_se.restored[0])
+ self.assertEqual(my_file, fake_se.restored[0])
class TestDeleteDirContents(MockerTestCase):
@@ -201,20 +204,20 @@ class TestDeleteDirContents(MockerTestCase):
self.assertDirEmpty(self.tmp)
-class TestKeyValStrings(TestCase):
+class TestKeyValStrings(unittest.TestCase):
def test_keyval_str_to_dict(self):
expected = {'1': 'one', '2': 'one+one', 'ro': True}
cmdline = "1=one ro 2=one+one"
self.assertEqual(expected, util.keyval_str_to_dict(cmdline))
-class TestGetCmdline(TestCase):
+class TestGetCmdline(unittest.TestCase):
def test_cmdline_reads_debug_env(self):
os.environ['DEBUG_PROC_CMDLINE'] = 'abcd 123'
self.assertEqual(os.environ['DEBUG_PROC_CMDLINE'], util.get_cmdline())
-class TestLoadYaml(TestCase):
+class TestLoadYaml(unittest.TestCase):
mydefault = "7b03a8ebace993d806255121073fed52"
def test_simple(self):