summaryrefslogtreecommitdiffstats
path: root/tests/command_context.py
blob: 1fe292555c94dbaaca7f8740f5f77b046b017ff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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>"

from os.path import join, dirname as d; execfile(join(d(d((__file__))), '_go'))


from unittest import TestCase

from .command_context import CommandContextBase


class TestCommandContextBase(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)


from os.path import join, dirname as d; execfile(join(d(__file__), '_gone'))