summaryrefslogtreecommitdiffstats
path: root/roles/lib_utils/src/test/unit/test_yedit.py
diff options
context:
space:
mode:
Diffstat (limited to 'roles/lib_utils/src/test/unit/test_yedit.py')
-rwxr-xr-xroles/lib_utils/src/test/unit/test_yedit.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/roles/lib_utils/src/test/unit/test_yedit.py b/roles/lib_utils/src/test/unit/test_yedit.py
index ed07ac96e..ce5e027a7 100755
--- a/roles/lib_utils/src/test/unit/test_yedit.py
+++ b/roles/lib_utils/src/test/unit/test_yedit.py
@@ -23,7 +23,7 @@ import unittest
yedit_path = os.path.join('/'.join(os.path.realpath(__file__).split('/')[:-4]), 'library') # noqa: E501
sys.path.insert(0, yedit_path)
-from yedit import Yedit # noqa: E402
+from yedit import Yedit, YeditException # noqa: E402
# pylint: disable=too-many-public-methods
# Silly pylint, moar tests!
@@ -200,6 +200,7 @@ class YeditTest(unittest.TestCase):
yed.append('x:y:z', [5, 6])
yed.append('x:y:z', [5, 6])
self.assertTrue(yed.get('x:y:z') == [1, 2, 3, [5, 6], [5, 6]])
+ # pylint: disable=maybe-no-member
self.assertTrue(2 == yed.get('x:y:z').count([5, 6]))
self.assertFalse(yed.exists('x:y:z', 4))
@@ -268,6 +269,24 @@ class YeditTest(unittest.TestCase):
yed.pop('a#b', 'c')
self.assertTrue({'a': {'b': {'d': 2}}} == yed.yaml_dict)
+ def test_accessing_path_with_unexpected_objects(self):
+ '''test providing source path objects that differ from current object state'''
+ yed = Yedit(content={'a': {'b': {'c': ['d', 'e']}}})
+ with self.assertRaises(YeditException):
+ yed.put('a.b.c.d', 'x')
+
+ def test_creating_new_objects_with_embedded_list(self):
+ '''test creating new objects with an embedded list in the creation path'''
+ yed = Yedit(content={'a': {'b': 12}})
+ with self.assertRaises(YeditException):
+ yed.put('new.stuff[0].here', 'value')
+
+ def test_creating_new_objects_with_trailing_list(self):
+ '''test creating new object(s) where the final piece is a list'''
+ yed = Yedit(content={'a': {'b': 12}})
+ with self.assertRaises(YeditException):
+ yed.put('new.stuff.here[0]', 'item')
+
def tearDown(self):
'''TearDown method'''
os.unlink(YeditTest.filename)