/usr/lib/python2.7/dist-packages/tables/tests/test_index_backcompat.py is in python-tables 3.4.2-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | # -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import absolute_import
from tables.tests import common
from tables.tests.common import verbose
from tables.tests.common import unittest, test_filename
from tables.tests.common import PyTablesTestCase as TestCase
from six.moves import range
# Check indexes from PyTables version 2.0
class IndexesTestCase(common.TestFileMixin, TestCase):
def setUp(self):
super(IndexesTestCase, self).setUp()
self.table1 = self.h5file.root.table1
self.table2 = self.h5file.root.table2
self.il = 0
self.sl = self.table1.cols.var1.index.slicesize
def test00_version(self):
"""Checking index version."""
t1var1 = self.table1.cols.var1
if "2_0" in self.h5fname:
self.assertEqual(t1var1.index._v_version, "2.0")
elif "2_1" in self.h5fname:
self.assertEqual(t1var1.index._v_version, "2.1")
def test01_string(self):
"""Checking string indexes."""
if common.verbose:
print('\n', '-=' * 30)
print("Running %s.test01_string..." % self.__class__.__name__)
table1 = self.table1
table2 = self.table2
# Convert the limits to the appropriate type
il = str(self.il).encode('ascii')
sl = str(self.sl).encode('ascii')
# Do some selections and check the results
# First selection
t1var1 = table1.cols.var1
self.assertTrue(t1var1 is not None)
results1 = [p["var1"] for p in
table1.where('(il<=t1var1)&(t1var1<=sl)')]
results2 = [p["var1"] for p in table2 if il <= p["var1"] <= sl]
results1.sort()
results2.sort()
if verbose:
print("Should look like:", results2)
print("Length results:", len(results1))
print("Should be:", len(results2))
self.assertEqual(len(results1), len(results2))
self.assertEqual(results1, results2)
def test02_bool(self):
"""Checking bool indexes."""
if common.verbose:
print('\n', '-=' * 30)
print("Running %s.test02_bool..." % self.__class__.__name__)
table1 = self.table1
table2 = self.table2
# Do some selections and check the results
t1var2 = table1.cols.var2
self.assertTrue(t1var2 is not None)
results1 = [p["var2"] for p in table1.where('t1var2 == True')]
results2 = [p["var2"] for p in table2 if p["var2"] is True]
if verbose:
print("Selection results (index):", results1)
print("Should look like:", results2)
print("Length results:", len(results1))
print("Should be:", len(results2))
self.assertEqual(len(results1), len(results2))
self.assertEqual(results1, results2)
def test03_int(self):
"""Checking int indexes."""
if common.verbose:
print('\n', '-=' * 30)
print("Running %s.test03_int..." % self.__class__.__name__)
table1 = self.table1
table2 = self.table2
# Convert the limits to the appropriate type
il = int(self.il)
sl = int(self.sl)
# Do some selections and check the results
t1col = table1.cols.var3
self.assertTrue(t1col is not None)
# First selection
results1 = [p["var3"] for p in table1.where('(il<=t1col)&(t1col<=sl)')]
results2 = [p["var3"] for p in table2
if il <= p["var3"] <= sl]
# sort lists (indexing does not guarantee that rows are returned in
# order)
results1.sort()
results2.sort()
if verbose:
print("Length results:", len(results1))
print("Should be:", len(results2))
self.assertEqual(len(results1), len(results2))
self.assertEqual(results1, results2)
def test04_float(self):
"""Checking float indexes."""
if common.verbose:
print('\n', '-=' * 30)
print("Running %s.test04_float..." % self.__class__.__name__)
table1 = self.table1
table2 = self.table2
# Convert the limits to the appropriate type
il = float(self.il)
sl = float(self.sl)
# Do some selections and check the results
t1col = table1.cols.var4
self.assertTrue(t1col is not None)
# First selection
results1 = [p["var4"] for p in table1.where('(il<=t1col)&(t1col<=sl)')]
results2 = [p["var4"] for p in table2
if il <= p["var4"] <= sl]
# sort lists (indexing does not guarantee that rows are returned in
# order)
results1.sort()
results2.sort()
if verbose:
print("Length results:", len(results1))
print("Should be:", len(results2))
self.assertEqual(len(results1), len(results2))
self.assertEqual(results1.sort(), results2.sort())
# Check indexes from PyTables version 2.0
class Indexes2_0TestCase(IndexesTestCase):
h5fname = test_filename("indexes_2_0.h5")
# Check indexes from PyTables version 2.1
class Indexes2_1TestCase(IndexesTestCase):
h5fname = test_filename("indexes_2_1.h5")
def suite():
theSuite = unittest.TestSuite()
niter = 1
for n in range(niter):
theSuite.addTest(unittest.makeSuite(Indexes2_0TestCase))
theSuite.addTest(unittest.makeSuite(Indexes2_1TestCase))
return theSuite
if __name__ == '__main__':
import sys
common.parse_argv(sys.argv)
common.print_versions()
unittest.main(defaultTest='suite')
|