• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / RestrictedPython / 11101164962

30 Sep 2024 07:10AM UTC coverage: 98.863%. Remained the same
11101164962

push

github

icemac
Back to development: 7.4

317 of 331 branches covered (95.77%)

2522 of 2551 relevant lines covered (98.86%)

0.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.98
/tests/builtins/test_utilities.py
1
import math
1✔
2
import random
1✔
3
import string
1✔
4

5

6
def test_string_in_utility_builtins():
1✔
7
    from RestrictedPython.Utilities import utility_builtins
1✔
8

9
    # we no longer provide access to ``string`` itself, only to
10
    # a restricted view of it (``rstring``)
11
    rstring = utility_builtins['string']
1✔
12
    assert rstring.__name__ == string.__name__
1✔
13

14
    # ensure it does not provide access to ``string`` via
15
    # ``AttributeError.obj``
16
    try:
1✔
17
        rstring.unexisting_attribute
1✔
18
    except AttributeError as e:
1✔
19
        assert e.obj is rstring
1✔
20

21

22
def test_math_in_utility_builtins():
1✔
23
    from RestrictedPython.Utilities import utility_builtins
1✔
24
    assert utility_builtins['math'] is math
1✔
25

26

27
def test_whrandom_in_utility_builtins():
1✔
28
    from RestrictedPython.Utilities import utility_builtins
1✔
29
    assert utility_builtins['whrandom'] is random
1✔
30

31

32
def test_random_in_utility_builtins():
1✔
33
    from RestrictedPython.Utilities import utility_builtins
1✔
34
    assert utility_builtins['random'] is random
1✔
35

36

37
def test_set_in_utility_builtins():
1✔
38
    from RestrictedPython.Utilities import utility_builtins
1✔
39
    assert utility_builtins['set'] is set
1✔
40

41

42
def test_frozenset_in_utility_builtins():
1✔
43
    from RestrictedPython.Utilities import utility_builtins
1✔
44
    assert utility_builtins['frozenset'] is frozenset
1✔
45

46

47
def test_DateTime_in_utility_builtins_if_importable():
1✔
48
    try:
1✔
49
        import DateTime
1✔
50
    except ImportError:
51
        pass
52
    else:
53
        from RestrictedPython.Utilities import utility_builtins
×
54
        assert DateTime.__name__ in utility_builtins
×
55

56

57
def test_same_type_in_utility_builtins():
1✔
58
    from RestrictedPython.Utilities import same_type
1✔
59
    from RestrictedPython.Utilities import utility_builtins
1✔
60
    assert utility_builtins['same_type'] is same_type
1✔
61

62

63
def test_test_in_utility_builtins():
1✔
64
    from RestrictedPython.Utilities import test
1✔
65
    from RestrictedPython.Utilities import utility_builtins
1✔
66
    assert utility_builtins['test'] is test
1✔
67

68

69
def test_reorder_in_utility_builtins():
1✔
70
    from RestrictedPython.Utilities import reorder
1✔
71
    from RestrictedPython.Utilities import utility_builtins
1✔
72
    assert utility_builtins['reorder'] is reorder
1✔
73

74

75
def test_sametype_only_one_arg():
1✔
76
    from RestrictedPython.Utilities import same_type
1✔
77
    assert same_type(object())
1✔
78

79

80
def test_sametype_only_two_args_same():
1✔
81
    from RestrictedPython.Utilities import same_type
1✔
82
    assert same_type(object(), object())
1✔
83

84

85
def test_sametype_only_two_args_different():
1✔
86
    from RestrictedPython.Utilities import same_type
1✔
87

88
    class Foo:
1✔
89
        pass
1✔
90
    assert same_type(object(), Foo()) is False
1✔
91

92

93
def test_sametype_only_multiple_args_same():
1✔
94
    from RestrictedPython.Utilities import same_type
1✔
95
    assert same_type(object(), object(), object(), object())
1✔
96

97

98
def test_sametype_only_multipe_args_one_different():
1✔
99
    from RestrictedPython.Utilities import same_type
1✔
100

101
    class Foo:
1✔
102
        pass
1✔
103
    assert same_type(object(), object(), Foo()) is False
1✔
104

105

106
def test_test_single_value_true():
1✔
107
    from RestrictedPython.Utilities import test
1✔
108
    assert test(True) is True
1✔
109

110

111
def test_test_single_value_False():
1✔
112
    from RestrictedPython.Utilities import test
1✔
113
    assert test(False) is False
1✔
114

115

116
def test_test_even_values_first_true():
1✔
117
    from RestrictedPython.Utilities import test
1✔
118
    assert test(True, 'first', True, 'second') == 'first'
1✔
119

120

121
def test_test_even_values_not_first_true():
1✔
122
    from RestrictedPython.Utilities import test
1✔
123
    assert test(False, 'first', True, 'second') == 'second'
1✔
124

125

126
def test_test_odd_values_first_true():
1✔
127
    from RestrictedPython.Utilities import test
1✔
128
    assert test(True, 'first', True, 'second', False) == 'first'
1✔
129

130

131
def test_test_odd_values_not_first_true():
1✔
132
    from RestrictedPython.Utilities import test
1✔
133
    assert test(False, 'first', True, 'second', False) == 'second'
1✔
134

135

136
def test_test_odd_values_last_true():
1✔
137
    from RestrictedPython.Utilities import test
1✔
138
    assert test(False, 'first', False, 'second', 'third') == 'third'
1✔
139

140

141
def test_test_odd_values_last_false():
1✔
142
    from RestrictedPython.Utilities import test
1✔
143
    assert test(False, 'first', False, 'second', False) is False
1✔
144

145

146
def test_reorder_with__None():
1✔
147
    from RestrictedPython.Utilities import reorder
1✔
148
    before = ['a', 'b', 'c', 'd', 'e']
1✔
149
    without = ['a', 'c', 'e']
1✔
150
    after = reorder(before, without=without)
1✔
151
    assert after == [('b', 'b'), ('d', 'd')]
1✔
152

153

154
def test_reorder_with__not_None():
1✔
155
    from RestrictedPython.Utilities import reorder
1✔
156
    before = ['a', 'b', 'c', 'd', 'e']
1✔
157
    with_ = ['a', 'd']
1✔
158
    without = ['a', 'c', 'e']
1✔
159
    after = reorder(before, with_=with_, without=without)
1✔
160
    assert after == [('d', 'd')]
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc