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

zopefoundation / Zope / 3956162881

pending completion
3956162881

push

github

Michael Howitz
Update to deprecation warning free releases.

4401 of 7036 branches covered (62.55%)

Branch coverage included in aggregate %.

27161 of 31488 relevant lines covered (86.26%)

0.86 hits per line

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

77.36
/src/Products/PageTemplates/tests/util.py
1
##############################################################################
2
#
3
# Copyright (c) 2002 Zope Foundation and Contributors.
4
#
5
# This software is subject to the provisions of the Zope Public License,
6
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
7
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10
# FOR A PARTICULAR PURPOSE
11
#
12
##############################################################################
13

14
import os
1✔
15
import os.path
1✔
16
import re
1✔
17
import sys
1✔
18
import unittest
1✔
19

20
from ExtensionClass import Base
1✔
21
from Products.PageTemplates.engine import Program
1✔
22
from zope.component import provideUtility
1✔
23
from zope.pagetemplate.interfaces import IPageTemplateEngine
1✔
24
from zope.pagetemplate.pagetemplate import PageTemplateEngine
1✔
25

26

27
# Dummy TestCase to use the assertions outside the actual tests.
28
TEST_CASE = unittest.TestCase('__init__')
1✔
29

30

31
class Bruce(Base):
1✔
32
    __allow_access_to_unprotected_subobjects__ = 1
1✔
33
    isDocTemp = 0
1✔
34

35
    def __str__(self):
1✔
36
        return 'bruce'
×
37

38
    def __int__(self):
1✔
39
        return 42
×
40

41
    def __float__(self):
1✔
42
        return 42.0
×
43

44
    def keys(self):
1✔
45
        return ['bruce'] * 7
×
46

47
    def values(self):
1✔
48
        return [self] * 7
×
49

50
    def items(self):
1✔
51
        return [('bruce', self)] * 7
×
52

53
    def __len__(self):
1✔
54
        return 7
×
55

56
    def __getitem__(self, index):
1✔
57
        if isinstance(index, int) and (index < 0 or index > 6):
×
58
            raise IndexError(index)
×
59
        return self
×
60

61
    def __getattr__(self, name):
1✔
62
        if name[:1] == '_':
×
63
            raise AttributeError(name)
×
64
        return self
×
65

66

67
bruce = Bruce()
1✔
68

69

70
class arg(Base):
1✔
71
    __allow_access_to_unprotected_subobjects__ = 1
1✔
72

73
    def __init__(self, nn, aa):
1✔
74
        self.num, self.arg = nn, aa
1✔
75

76
    def __str__(self):
1✔
77
        return str(self.arg)
1✔
78

79

80
class argv(Base):
1✔
81
    __allow_access_to_unprotected_subobjects__ = 1
1✔
82

83
    def __init__(self, argv=sys.argv[1:]):
1✔
84
        args = self.args = []
1✔
85
        for aa in argv:
1✔
86
            args.append(arg(len(args) + 1, aa))
1✔
87

88
    def items(self):
1✔
89
        return [('spam%d' % a.num, a) for a in self.args]
×
90

91
    def values(self):
1✔
92
        return self.args
×
93

94
    def getPhysicalRoot(self):
1✔
95
        return self
×
96

97

98
def check_html(s1, s2):
1✔
99
    if not isinstance(s2, bytes) and isinstance(s1, bytes):
1!
100
        # convert to common type
101
        s1 = s1.decode("utf-8")  # our encoding
×
102
    s1 = normalize_html(s1)
1✔
103
    s2 = normalize_html(s2)
1✔
104
    TEST_CASE.assertEqual(s1, s2)
1✔
105

106

107
def check_xml(s1, s2):
1✔
108
    s1 = normalize_xml(s1)
1✔
109
    s2 = normalize_xml(s2)
1✔
110
    TEST_CASE.assertEqual(s1, s2, "XML Output Changed")
1✔
111

112

113
def normalize_html(s):
1✔
114
    s = re.sub(r"[ \t]+", " ", s)
1✔
115
    s = re.sub(r"/>", ">", s)
1✔
116
    return s
1✔
117

118

119
def normalize_xml(s):
1✔
120
    s = re.sub(r"\s+", " ", s)
1✔
121
    s = re.sub(r"(?s)\s+<", "<", s)
1✔
122
    s = re.sub(r"(?s)>\s+", ">", s)
1✔
123
    return s
1✔
124

125

126
HERE = os.path.dirname(__file__)
1✔
127
input_dir = os.path.join(HERE, 'input')
1✔
128
output_dir = os.path.join(HERE, 'output')
1✔
129

130

131
def _open(filename, mode):
1✔
132
    # Define explicit encoding for windows platform
133
    return open(filename, mode, encoding='utf-8')
1✔
134

135

136
def read_input(filename):
1✔
137
    filename = os.path.join(input_dir, filename)
1✔
138
    with _open(filename, 'r') as fd:
1✔
139
        data = fd.read()
1✔
140
    return data
1✔
141

142

143
def read_output(filename):
1✔
144
    filename = os.path.join(output_dir, filename)
1✔
145
    with _open(filename, 'r') as fd:
1✔
146
        data = fd.read()
1✔
147
    return data
1✔
148

149

150
def exists_output(filename):
1✔
151
    filename = os.path.join(output_dir, filename)
1✔
152
    return os.path.exists(filename)
1✔
153

154

155
def useChameleonEngine():
1✔
156
    # Force the use of the new chameleon rendering engine (the new default).
157
    # Its use depends on a utility registration that is queried in
158
    # zope.pagetemplate,pagetemplate.PageTemplate's _cook method. Unfortunately
159
    # the fallback is the old Zope engine if there is no registration, so we
160
    # force one here for use by unit tests.
161
    provideUtility(Program, IPageTemplateEngine)
1✔
162

163

164
def useOldZopeEngine():
1✔
165
    # BBB Force the use of the old Zope page template engine, which is needed
166
    # for some tests that test features only supported by it.
167
    provideUtility(PageTemplateEngine, IPageTemplateEngine)
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