summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2014-06-19 20:08:57 +0200
committerJan Pokorný <jpokorny@redhat.com>2014-06-19 20:09:31 +0200
commit881c2644471b2c9ba3a675b5b629aaf867e974aa (patch)
treec1089c829cfd70b85fbfe745b5fcc493ca89aac2 /tests
parent11ededc00f5dbe6ff50bee75d7340b24950996c8 (diff)
downloadclufter-881c2644471b2c9ba3a675b5b629aaf867e974aa.tar.gz
clufter-881c2644471b2c9ba3a675b5b629aaf867e974aa.tar.xz
clufter-881c2644471b2c9ba3a675b5b629aaf867e974aa.zip
tests/command_context: check proper "notaint" + "anabasis"
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/command_context.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/command_context.py b/tests/command_context.py
new file mode 100644
index 0000000..1076bdf
--- /dev/null
+++ b/tests/command_context.py
@@ -0,0 +1,61 @@
+# -*- coding: UTF-8 -*-
+# Copyright 2014 Red Hat, Inc.
+# Part of clufter project
+# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
+"""Testing command context"""
+__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"
+
+import unittest
+
+import _bootstrap # known W402, required
+
+from clufter.command_context import CommandContextBase
+
+
+class TestCommandContextBase(unittest.TestCase):
+ def testAnabasisConstructor(self):
+ ccb = CommandContextBase({'a': {'b': {'c': {'d': {'e': 42}}}}})
+ e = ccb['a']['b']['c']['d']
+ self.assertTrue(len(tuple(e.anabasis())) == 5)
+
+ def testAnabasisBuilt(self):
+ ccb = CommandContextBase()
+ ccb['a'] = {'b': {'c': {'d': {'e': 42}}}}
+ e = ccb['a']['b']['c']['d']
+ self.assertTrue(len(tuple(e.anabasis())) == 5)
+
+ def testPreventedTaint(self):
+ ccb = CommandContextBase({'a': 42})
+ with ccb.prevented_taint():
+ try:
+ ccb['a'] = 43
+ except RuntimeError:
+ self.assertTrue(ccb['a'] == 42)
+ else:
+ self.assertTrue(False)
+ try:
+ ccb['a'] = 43
+ except RuntimeError:
+ self.assertTrue(False)
+ else:
+ self.assertTrue(ccb['a'] == 43)
+
+ def testPreventedTaintTransitive(self):
+ ccb = CommandContextBase({'a': {'b': 42}})
+ with ccb.prevented_taint():
+ try:
+ ccb['a']['b'] = 43
+ except RuntimeError:
+ self.assertTrue(ccb['a']['b'] == 42)
+ else:
+ self.assertTrue(False)
+ try:
+ ccb['a']['b'] = 43
+ except RuntimeError:
+ self.assertTrue(False)
+ else:
+ self.assertTrue(ccb['a']['b'] == 43)
+
+
+if __name__ == '__main__':
+ unittest.main()