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

zopefoundation / Products.ZSQLMethods / 15955029452

20 Mar 2025 07:15AM UTC coverage: 73.093% (-0.8%) from 73.918%
15955029452

push

github

web-flow
Update Python version support. (#50)

* Drop support for Python 3.8.

* Add support for Python 3.13.

* Configuring for zope-product

* Update Python version support.

337 of 630 branches covered (53.49%)

Branch coverage included in aggregate %.

6 of 6 new or added lines in 3 files covered. (100.0%)

4 existing lines in 1 file now uncovered.

2116 of 2726 relevant lines covered (77.62%)

0.78 hits per line

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

97.26
/src/Shared/DC/ZRDB/tests/test_results.py
1
""" Unit tests for Products.RHGDelivery.simpleresults
2
"""
3
import sys
1✔
4
import unittest
1✔
5

6
from Acquisition import aq_parent
1✔
7
from ExtensionClass import Base
1✔
8

9

10
class Brain:
1✔
11
    def __init__(self, *args):
1✔
12
        pass
1✔
13

14

15
Parent = Base()
1✔
16

17

18
class TestResults(unittest.TestCase):
1✔
19

20
    # test fixtures
21
    columns = [{'name': 'string', 'type': 't', 'width': 1},
1✔
22
               {'name': 'int', 'type': 'i'}]
23
    data = [['string1', 1], ['string2', 2]]
1✔
24

25
    def _getTargetClass(self):
1✔
26
        from Shared.DC.ZRDB.Results import Results
1✔
27
        return Results
1✔
28

29
    def _makeOne(self, *args, **kw):
1✔
30
        return self._getTargetClass()(*args, **kw)
1✔
31

32
    def test_searchable_result_columns(self):
1✔
33
        ob = self._makeOne((self.columns, self.data))
1✔
34
        self.assertEqual(ob._searchable_result_columns(), self.columns)
1✔
35

36
    def test_names(self):
1✔
37
        ob = self._makeOne((self.columns, self.data))
1✔
38
        self.assertEqual(ob.names(), ['string', 'int'])
1✔
39

40
    def test_data_dictionary(self):
1✔
41
        ob = self._makeOne((self.columns, self.data))
1✔
42
        self.assertEqual(
1✔
43
            ob.data_dictionary(),
44
            {'string': {'name': 'string', 'type': 't', 'width': 1},
45
             'int': {'name': 'int', 'type': 'i'}})
46

47
    def test_len(self):
1✔
48
        ob = self._makeOne((self.columns, self.data))
1✔
49
        self.assertEqual(len(ob), 2)
1✔
50

51
    def test_getitem(self):
1✔
52
        ob = self._makeOne((self.columns, self.data))
1✔
53
        row = ob[0]
1✔
54
        self.assertEqual(row[0], 'string1')
1✔
55
        self.assertEqual(row[1], 1)
1✔
56
        row = ob[1]
1✔
57
        self.assertEqual(row[0], 'string2')
1✔
58
        self.assertEqual(row[1], 2)
1✔
59

60
    def test_getattr_and_aliases(self):
1✔
61
        ob = self._makeOne((self.columns, self.data))
1✔
62
        row = ob[0]
1✔
63
        self.assertEqual(row.string, 'string1')
1✔
64
        self.assertEqual(row.int, 1)
1✔
65
        self.assertEqual(row.STRING, 'string1')
1✔
66
        self.assertEqual(row.INT, 1)
1✔
67
        row = ob[1]
1✔
68
        self.assertEqual(row.string, 'string2')
1✔
69
        self.assertEqual(row.int, 2)
1✔
70
        self.assertEqual(row.STRING, 'string2')
1✔
71
        self.assertEqual(row.INT, 2)
1✔
72

73
    def test_suppliedbrain(self):
1✔
74
        ob = self._makeOne((self.columns, self.data), brains=Brain)
1✔
75
        row = ob[0]
1✔
76
        self.assertIsInstance(row, Brain)
1✔
77

78
    def test_suppliedparent(self):
1✔
79
        ob = self._makeOne((self.columns, self.data), parent=Parent)
1✔
80
        row = ob[0]
1✔
81
        self.assertIs(aq_parent(row), Parent)
1✔
82

83
    def test_tuples(self):
1✔
84
        ob = self._makeOne((self.columns, self.data))
1✔
85
        tuples = ob.tuples()
1✔
86
        self.assertEqual(tuples, [('string1', 1), ('string2', 2)])
1✔
87

88
    def test_dictionaries(self):
1✔
89
        ob = self._makeOne((self.columns, self.data))
1✔
90
        dicts = ob.dictionaries()
1✔
91
        self.assertEqual(dicts, [{'string': 'string1', 'int': 1},
1✔
92
                                 {'string': 'string2', 'int': 2}])
93

94
    def test_asRDB(self):
1✔
95
        ob = self._makeOne((self.columns, self.data))
1✔
96
        asrdb = ob.asRDB()
1✔
97
        columns = ['string\tint', '1t\ti', 'string1\t1', 'string2\t2\n']
1✔
98
        self.assertEqual(asrdb, '\n'.join(columns))
1✔
99

100
    def _set_noschema(self, row):
1✔
101
        row.cantdoit = 1
1✔
102

103
    def test_recordschema(self):
1✔
104
        ob = self._makeOne((self.columns, self.data))
1✔
105
        row = ob[0]
1✔
106
        self.assertEqual(row.__record_schema__, {'string': 0, 'int': 1})
1✔
107
        self.assertRaises(AttributeError, self._set_noschema, row)
1✔
108

109
    def test_record_as_read_mapping(self):
1✔
110
        ob = self._makeOne((self.columns, self.data))
1✔
111
        row = ob[0]
1✔
112
        self.assertEqual('%(string)s %(int)s' % row, 'string1 1')
1✔
113
        row = ob[1]
1✔
114
        self.assertEqual('%(string)s %(int)s' % row, 'string2 2')
1✔
115

116
    def test_record_as_write_mapping(self):
1✔
117
        ob = self._makeOne((self.columns, self.data))
1✔
118
        row = ob[0]
1✔
119
        row['int'] = 5
1✔
120
        self.assertEqual('%(string)s %(int)s' % row, 'string1 5')
1✔
121

122
    def test_record_as_write_mapping2(self):
1✔
123
        ob = self._makeOne((self.columns, self.data))
1✔
124
        row = ob[0]
1✔
125
        row.int = 5
1✔
126
        self.assertEqual('%(string)s %(int)s' % row, 'string1 5')
1✔
127

128
    def test_record_as_sequence(self):
1✔
129
        ob = self._makeOne((self.columns, self.data))
1✔
130
        row = ob[0]
1✔
131
        self.assertEqual(row[0], 'string1')
1✔
132
        self.assertEqual(row[1], 1)
1✔
133
        self.assertEqual(list(row), ['string1', 1])
1✔
134
        row = ob[1]
1✔
135
        self.assertEqual(row[0], 'string2')
1✔
136
        self.assertEqual(row[1], 2)
1✔
137
        self.assertEqual(list(row), ['string2', 2])
1✔
138

139
    def test_record_of(self):
1✔
140
        ob = self._makeOne((self.columns, self.data))
1✔
141
        row = ob[0]
1✔
142
        wrapped = row.__of__(Parent)
1✔
143
        self.assertEqual(wrapped.aq_self, row)
1✔
144
        self.assertEqual(wrapped.aq_parent, Parent)
1✔
145

146
    def test_record_hash(self):
1✔
147
        ob = self._makeOne((self.columns, self.data))
1✔
148
        row = ob[0]
1✔
149
        self.assertIsInstance(hash(row), int)
1✔
150

151
    def test_record_len(self):
1✔
152
        ob = self._makeOne((self.columns, self.data))
1✔
153
        row = ob[0]
1✔
154
        self.assertEqual(len(row), 2)
1✔
155

156
    def _add(self, row1, row2):
1✔
157
        return row1 + row2
1✔
158

159
    def test_record_add(self):
1✔
160
        ob = self._makeOne((self.columns, self.data))
1✔
161
        row1 = ob[0]
1✔
162
        row2 = ob[1]
1✔
163
        self.assertRaises(TypeError, self._add, row1, row2)
1✔
164

165
    def _slice(self, row):
1✔
UNCOV
166
        return row[1:]
×
167

168
    @unittest.skipIf(sys.version_info >= (3, 12),
1✔
169
                     'Only valid before Python 3.12')
170
    def test_record_slice(self):
1✔
171
        # This test relies on the fact that instances of class slice
172
        # are unhashable and they cannot be used as keys. However,
173
        # Python 3.12 made slice instances hashable, so this test
174
        # no longer makes sense there.
UNCOV
175
        ob = self._makeOne((self.columns, self.data))
×
UNCOV
176
        row = ob[0]
×
UNCOV
177
        self.assertRaises(TypeError, self._slice, row)
×
178

179
    def _mul(self, row):
1✔
180
        return row * 3
1✔
181

182
    def test_record_mul(self):
1✔
183
        ob = self._makeOne((self.columns, self.data))
1✔
184
        row = ob[0]
1✔
185
        self.assertRaises(TypeError, self._mul, row)
1✔
186

187
    def _del(self, row):
1✔
188
        del row[0]
1✔
189

190
    def test_record_delitem(self):
1✔
191
        ob = self._makeOne((self.columns, self.data))
1✔
192
        row = ob[0]
1✔
193
        self.assertRaises(TypeError, self._del, row)
1✔
194

195

196
def test_suite():
1✔
197
    suite = unittest.TestSuite()
1✔
198
    suite.addTest(
1✔
199
        unittest.defaultTestLoader.loadTestsFromTestCase(TestResults))
200
    return suite
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