File: test_context.py

package info (click to toggle)
glitch 0.6-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 488 kB
  • ctags: 649
  • sloc: python: 3,432; makefile: 2
file content (114 lines) | stat: -rw-r--r-- 1,992 bytes parent folder | download | duplicates (2)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

def test_context_repr():
    """
    Context: Representation.

    >>> from glitch.context import Context
    >>> c = Context()

    >>> c
    Context({})
    >>> c = Context({'foo': 1})
    >>> c
    Context({'foo': 1})
    """

def test_context_get_set():
    """
    Context: Getting and setting values.

    >>> from glitch.context import Context
    >>> c = Context({'foo': 1})

    >>> c['foo']
    1
    >>> c['foo'] = 3
    >>> c['foo']
    3
    """

def test_context_push_pop():
    """
    Context: Pushing and popping.

    >>> from glitch.context import Context
    >>> c = Context()

    >>> c['bar'] = 2
    >>> c.push('bar') # doctest: +ELLIPSIS
    <...>
    >>> c['bar']
    2
    >>> c['bar'] = 4
    >>> c['bar']
    4
    >>> c.pop()
    >>> c['bar']
    2

    Pushing with value.

    >>> c.push('bar', 4) # doctest: +ELLIPSIS
    <...>
    >>> c['bar']
    4
    >>> c.pop()
    >>> c['bar']
    2
    """

def test_context_push_absent():
    """
    Context: Pushing an absent value.

    >>> from glitch.context import Context
    >>> c = Context()

    >>> c.push('baz') # doctest: +ELLIPSIS
    <...>
    >>> c['baz'] = 5
    >>> c['baz']
    5
    >>> c.pop()
    >>> 'baz' in c
    False

    Pushing a value that doesn't get set before getting popped.

    >>> c.push('quux') # doctest: +ELLIPSIS
    <...>
    >>> c.pop()
    """

def test_context_with():
    """
    Context: Using with statement.

    >>> from __future__ import with_statement

    >>> from glitch.context import Context
    >>> c = Context()

    >>> with c.push('quux'):
    ...     c['quux'] = 2
    ...
    >>> 'quux' in c
    False
    """

def test_context_copy():
    """
    Context: Pushing mutable values.

    >>> from __future__ import with_statement

    >>> from glitch.context import Context
    >>> c = Context()

    >>> c['x'] = {'a': 1, 'b': 2}
    >>> with c.push('x'):
    ...     c['x']['c'] = 3
    ...
    >>> sorted(c['x'].items())
    [('a', 1), ('b', 2)]
    """