Ejemplo n.º 1
0
    def test01_rowAppend(self):
        """Appending enumerated values using ``row.append()``."""

        tbl = self.h5file.createTable(
            '/', 'test', self._description(), title=self._getMethodName())

        appended = [
            (10, self.valueInEnum),
            (20, self.valueOutOfEnum)]

        row = tbl.row

        row['rid'] = appended[0][0]
        row['rcolor'] = appended[0][1]
        row.append()

        row['rid'] = appended[1][0]
        self.assertRaises(
            ValueError, operator.setitem, row, 'rcolor', appended[1][1])

        tbl.flush()
        tbl.flavor = 'python'
        read = tbl.read()
        common.verbosePrint(
            "* appended value: %s\n"
            "* read value: %s\n"
            % (appended[:-1], read) )
        self.assertEqual(
            appended[:-1], read, "Written and read values differ.")
Ejemplo n.º 2
0
    def testDescrStructure(self):
        """Check structure of the descr list.
        """

        common.verbosePrint('\nTesting descr structure')
        for item in nriterators.flattenDescr(self.descr, check=True):
            self.failIfEqual(item, None)
Ejemplo n.º 3
0
    def testSubFieldNames(self):
        """Check the syntax of the names list components.
        """

        common.verbosePrint('\nTesting names list decomposition')
        subnames = [sn for sn in nriterators.getSubNames(self.names)]
        self.assertEqual(subnames, self.subnames)
Ejemplo n.º 4
0
    def testDescrStructure(self):
        """Check structure of the descr list.
        """

        common.verbosePrint('\nTesting descr structure')
        for item in nriterators.flattenDescr(self.descr, check=True):
            self.failIfEqual(item, None)
Ejemplo n.º 5
0
    def testNamesUniqueness(self):
        """Check that names are unique at every level of the names list.
        """

        common.verbosePrint('\nTesting checkNamesUniqueness')
        foo = nriterators.checkNamesUniqueness
        badNames = [
            'info',
            ('info', [('name', ['first', 'second']), ('coord', ['x', 'y',
                                                                'z'])])
        ]
        self.assertRaises(ValueError, foo, badNames)
        badNames = [
            'position',
            ('info', [('coord', ['first', 'second']),
                      ('coord', ['x', 'y', 'z'])])
        ]
        self.assertRaises(ValueError, foo, badNames)
        badNames = [
            'position',
            ('info', [('name', ['first', 'second']), ('coord', ['x', 'x',
                                                                'z'])])
        ]
        self.assertRaises(ValueError, foo, badNames)
        goodNames = [
            'position',
            ('info', [('info', ['first', 'second']), ('coord', ['x', 'y',
                                                                'z'])])
        ]
        self.assertEqual(foo(goodNames), None)
Ejemplo n.º 6
0
    def testFormatsStructure(self):
        """Check the structure of the formats list.
        """

        common.verbosePrint('\nTesting formats structure')
        for f in nriterators.flattenFormats(self.formats, check=True):
            self.failIfEqual(f, None)
Ejemplo n.º 7
0
    def testSubFieldNames(self):
        """Check the syntax of the names list components.
        """

        common.verbosePrint('\nTesting names list decomposition')
        subnames = [sn for sn in nriterators.getSubNames(self.names)]
        self.assertEqual(subnames, self.subnames)
Ejemplo n.º 8
0
    def test01_rowAppend(self):
        """Appending enumerated values using ``row.append()``."""

        tbl = self.h5file.create_table(
            '/', 'test', self._description(), title=self._getMethodName())

        appended = [
            (10, self.valueInEnum),
            (20, self.valueOutOfEnum)]

        row = tbl.row

        row['rid'] = appended[0][0]
        row['rcolor'] = appended[0][1]
        row.append()

        row['rid'] = appended[1][0]
        self.assertRaises(
            ValueError, operator.setitem, row, 'rcolor', appended[1][1])

        tbl.flush()
        tbl.flavor = 'python'
        read = tbl.read()
        common.verbosePrint(
            "* appended value: %s\n"
            "* read value: %s\n"
            % (appended[:-1], read))
        self.assertEqual(
            appended[:-1], read, "Written and read values differ.")
Ejemplo n.º 9
0
    def testArrayNames(self):
        """Check the checkNames function.
        """

        common.verbosePrint('\nTesting samples of names description')
        names = 'names should be a list'
        self.assertRaises(TypeError, nra.nestedrecords._checkNames, names)
        # Names must be a list of strings or 2-tuples
        names = [
            25,
            ('info', [('name', ['first', 'second']), ('coord', ['x', 'y',
                                                                'z'])])
        ]
        self.assertRaises(TypeError, nra.nestedrecords._checkNames, names)

        # Names must be unique at any given level
        names = [
            'position',
            ('info', [('name', ['first', 'second']), ('coord', ['x', 'y',
                                                                'y'])])
        ]
        self.assertRaises(ValueError, nra.nestedrecords._checkNames, names)

        # If names is OK checkNames returns None
        self.assertEqual(nra.nestedrecords._checkNames(self.names), None)
Ejemplo n.º 10
0
    def testNamesStructure(self):
        """Check the structure of the names list.
        """

        common.verbosePrint('\nTesting names structure')
        for item in nriterators.flattenNames(self.names):
            self.failIfEqual(item, None)
Ejemplo n.º 11
0
    def testArrayDescr(self):
        """Check the checkDescr function.
        """

        common.verbosePrint('\nTesting samples of descr description')
        # Descr must be a list of 2-tuples
        descr = 'some descr specification'
        self.assertRaises(TypeError, nra.nestedrecords._checkDescr, descr)

        # names in descr must be strings
        # formats must be strings or list of 2-tuples
        descr = [(25, 'Int64'),
                 ('info', [('name', [('first', 'a5'), ('second', 'a5')]),
                           ('coord', [('x', 'Float32'), ('y', 'f4'),
                                      ('z', 'f4')])])]
        self.assertRaises(TypeError, nra.nestedrecords._checkDescr, descr)

        descr = [('25', 'position', 'Int64'),
                 ('info', [('name', [('first', 'a5'), ('second', 'a5')]),
                           ('coord', [('x', 'Float32'), ('y', 'f4'),
                                      ('z', 'f4')])])]
        self.assertRaises(TypeError, nra.nestedrecords._checkDescr, descr)

        # If descr is OK checkDescr returns None
        self.assertEqual(nra.nestedrecords._checkDescr(self.descr), None)
Ejemplo n.º 12
0
    def test05_where(self):
        """Searching enumerated data."""

        tbl = self.h5file.createTable('/',
                                      'test',
                                      self._description(),
                                      title=self._getMethodName())

        appended = [(10, self.valueInEnum), (20, self.valueInEnum),
                    (30, self.valueOutOfEnum)]
        tbl.append(appended)
        tbl.flush()

        searched = [
            (row['rid'], row['rcolor'])
            for row in tbl.where('rcolor == v', {'v': self.valueInEnum})
        ]
        common.verbosePrint(
            "* ``valueInEnum``: %s\n"
            "* ``rcolor`` column: ``%s``\n"
            "* ``searched``: %s\n"
            "* Should look like: %s\n" %
            (self.valueInEnum, tbl.cols.rcolor, searched, appended[:-1]))
        self.assertEqual(searched, appended[:-1],
                         "Search returned incorrect results.")
Ejemplo n.º 13
0
 def test(self):
     for condition in self.conditions:
         c_usable_idxs = self.will_query_use_indexing(condition, {})
         self.assertEqual(c_usable_idxs, self.usable_idxs,
                          "\nQuery with condition: ``%s``\n"
                          "Computed usable indexes are: ``%s``\n"
                          "and should be: ``%s``" %
                         (condition, c_usable_idxs, self.usable_idxs))
         condvars = self.requiredExprVars(condition, None)
         compiled = self.compileCondition(condition, condvars)
         c_idx_expr = compiled.index_expressions
         self.assertEqual(c_idx_expr, self.idx_expr,
                          "\nWrong index expression in condition:\n``%s``\n"
                          "Compiled index expression is:\n``%s``\n"
                          "and should be:\n``%s``" %
                         (condition, c_idx_expr, self.idx_expr))
         c_str_expr = compiled.string_expression
         self.assertEqual(c_str_expr, self.str_expr,
                          "\nWrong index operations in condition:\n``%s``\n"
                          "Computed index operations are:\n``%s``\n"
                          "and should be:\n``%s``" %
                         (condition, c_str_expr, self.str_expr))
         common.verbosePrint("* Query with condition ``%s`` will use "
                "variables ``%s`` for indexing."
                % (condition, compiled.index_variables))
Ejemplo n.º 14
0
    def testFormatsStructure(self):
        """Check the structure of the formats list.
        """

        common.verbosePrint('\nTesting formats structure')
        for f in nriterators.flattenFormats(self.formats, check=True):
            self.failIfEqual(f, None)
Ejemplo n.º 15
0
    def testNamesStructure(self):
        """Check the structure of the names list.
        """

        common.verbosePrint('\nTesting names structure')
        for item in nriterators.flattenNames(self.names):
            self.failIfEqual(item, None)
Ejemplo n.º 16
0
    def testBufferStructureWDescr(self):
        """Check the structure of a buffer row using the descr list.
        """

        common.verbosePrint('\nTesting buffer row structure with zipBufferDescr')
        mix = [item for item in nriterators.zipBufferDescr(self.row,
            self.descr)]
        self.assertEqual(mix, zip(self.flat_row, self.flat_formats))
Ejemplo n.º 17
0
    def testNamesFromDescr(self):
        """Retrieves the names list from the descr list.
        """

        # Check getNamesFromDescr function
        common.verbosePrint('\nTesting getNamesFromDescr function')
        new_names = \
            [item for item in nriterators.getNamesFromDescr(self.descr)]
        self.assertEqual(self.names, new_names)
Ejemplo n.º 18
0
    def testNamesFromDescr(self):
        """Retrieves the names list from the descr list.
        """

        # Check getNamesFromDescr function
        common.verbosePrint('\nTesting getNamesFromDescr function')
        new_names = \
            [item for item in nriterators.getNamesFromDescr(self.descr)]
        self.assertEqual(self.names, new_names)
Ejemplo n.º 19
0
    def testMakeDescr(self):
        """Check the generation of a descr from formats and names.
        """

        common.verbosePrint('\nTesting getDescr function')
        mix = [f for f in nriterators.getDescr(None, self.formats)]
        self.assertEqual(mix, self.autoNamedDescr)
        mix = \
            [f for f in nriterators.getDescr(self.names, self.formats)]
        self.assertEqual(mix, self.descr)
Ejemplo n.º 20
0
    def testBufferStructureWDescr(self):
        """Check the structure of a buffer row using the descr list.
        """

        common.verbosePrint(
            '\nTesting buffer row structure with zipBufferDescr')
        mix = [
            item for item in nriterators.zipBufferDescr(self.row, self.descr)
        ]
        self.assertEqual(mix, zip(self.flat_row, self.flat_formats))
Ejemplo n.º 21
0
    def testMakeDescr(self):
        """Check the generation of a descr from formats and names.
        """

        common.verbosePrint('\nTesting getDescr function')
        mix = [f for f in nriterators.getDescr(None, self.formats)]
        self.assertEqual(mix, self.autoNamedDescr)
        mix = \
            [f for f in nriterators.getDescr(self.names, self.formats)]
        self.assertEqual(mix, self.descr)
Ejemplo n.º 22
0
    def testFieldsDescr(self):
        """Check the checkFieldsInDescr function.
        """

        common.verbosePrint( """\nTesting the field names syntax in a """
            """sample descr list""")
        descr = [('position', 'Int64'),
            ('info', [('name', [('first','a5'), ('second','a5')]),
               ('coord', [('x/equis','Float32'), ('y', 'f4'), ('z', 'f4')])])]
        self.assertRaises(ValueError, nra.nestedrecords._checkFieldsInDescr,
            descr)
Ejemplo n.º 23
0
 def newmethod(self, *args, **kwargs):
     self._verboseHeader()
     try:
         return oldmethod(self, *args, **kwargs)
     except SilentlySkipTest as se:
         if se.args:
             msg = se.args[0]
         else:
             msg = "<skipped>"
         common.verbosePrint("\nSkipped test: %s" % msg)
     finally:
         common.verbosePrint('')  # separator line between tests
Ejemplo n.º 24
0
 def newmethod(self, *args, **kwargs):
     self._verboseHeader()
     try:
         return oldmethod(self, *args, **kwargs)
     except SilentlySkipTest as se:
         if se.args:
             msg = se.args[0]
         else:
             msg = "<skipped>"
         common.verbosePrint("\nSkipped test: %s" % msg)
     finally:
         common.verbosePrint('')  # separator line between tests
Ejemplo n.º 25
0
    def testFieldsDescr(self):
        """Check the checkFieldsInDescr function.
        """

        common.verbosePrint("""\nTesting the field names syntax in a """
                            """sample descr list""")
        descr = [('position', 'Int64'),
                 ('info', [('name', [('first', 'a5'), ('second', 'a5')]),
                           ('coord', [('x/equis', 'Float32'), ('y', 'f4'),
                                      ('z', 'f4')])])]
        self.assertRaises(ValueError, nra.nestedrecords._checkFieldsInDescr,
                          descr)
Ejemplo n.º 26
0
    def testArrayFormats(self):
        """Check the checkFormats function.
        """

        common.verbosePrint('\nTesting samples of formats description')
        formats = 'formats should be a list'
        self.assertRaises(TypeError, nra.nestedrecords._checkFormats, formats)
        # Formats must be a list of strings or sequences
        formats = [25, [['a5', 'a5'], ['Float32', 'f4', 'f4']]]
        self.assertRaises(TypeError, nra.nestedrecords._checkFormats, formats)
        # If formats is OK checkFormats returns None
        self.assertEqual(nra.nestedrecords._checkFormats(self.formats), None)
Ejemplo n.º 27
0
    def testArrayUniqueSyntax(self):
        """Check the onlyOneSyntax function.
        """

        common.verbosePrint( '\nTesting the uniqueness of the array syntax')
        self.assertEqual(nra.nestedrecords._onlyOneSyntax(self.descr, None,
            None), None)
        self.assertEqual(nra.nestedrecords._onlyOneSyntax(None,
            self.formats, None), None)
        self.assertRaises(ValueError, nra.nestedrecords._onlyOneSyntax,
            self.descr, self.formats, None)
        self.assertRaises(ValueError, nra.nestedrecords._onlyOneSyntax,
            self.descr, None, self.names)
Ejemplo n.º 28
0
    def test02_append(self):
        """Appending enumerated values using ``table.append()``."""

        tbl = self.h5file.create_table("/", "test", self._description(), title=self._getMethodName())

        appended = [(10, self.valueInEnum), (20, self.valueOutOfEnum)]

        tbl.append(appended)
        tbl.flush()
        tbl.flavor = "python"
        read = tbl.read()
        common.verbosePrint("* appended value: %s\n" "* read value: %s\n" % (appended, read))
        self.assertEqual(appended, read, "Written and read values differ.")
Ejemplo n.º 29
0
    def testArrayUniqueSyntax(self):
        """Check the onlyOneSyntax function.
        """

        common.verbosePrint('\nTesting the uniqueness of the array syntax')
        self.assertEqual(
            nra.nestedrecords._onlyOneSyntax(self.descr, None, None), None)
        self.assertEqual(
            nra.nestedrecords._onlyOneSyntax(None, self.formats, None), None)
        self.assertRaises(ValueError, nra.nestedrecords._onlyOneSyntax,
                          self.descr, self.formats, None)
        self.assertRaises(ValueError, nra.nestedrecords._onlyOneSyntax,
                          self.descr, None, self.names)
Ejemplo n.º 30
0
    def test03_setitem(self):
        """Changing enumerated values using ``table.__setitem__()``."""

        tbl = self.h5file.create_table("/", "test", self._description(), title=self._getMethodName())

        appended = [(10, self.valueInEnum), (20, self.valueInEnum)]
        tbl.append(appended)

        written = [(10, self.valueInEnum), (20, self.valueOutOfEnum)]
        tbl[:] = written
        tbl.flavor = "python"
        read = tbl.read()
        common.verbosePrint("* written value: %s\n" "* read value: %s\n" % (written, read))
        self.assertEqual(written, read, "Written and read values differ.")
Ejemplo n.º 31
0
    def test(self):
        """Reading scalar arrays (see #98)."""

        arr = self.h5file.createArray('/', 'scalar_na', 1234)
        arr.flavor = 'numarray'

        self._reopen()

        arr = self.h5file.root.scalar_na

        common.verbosePrint("* %r == %r ?" % (arr.read(), array(1234)))
        self.assertTrue(all(arr.read() == array(1234)))
        common.verbosePrint("* %r == %r ?" % (arr[()], array(1234)))
        self.assertTrue(all(arr[()] == 1234))
Ejemplo n.º 32
0
    def test01_append(self):
        """Appending scalar elements of enumerated values."""

        vlarr = self.h5file.create_vlarray("/", "test", self._atom(), title=self._getMethodName())
        vlarr.flavor = "python"

        appended = [[self.valueInEnum], [self.valueInEnum, self.valueOutOfEnum]]

        vlarr.append(appended[0])
        vlarr.append(appended[1])
        vlarr.flush()
        read = vlarr.read()
        common.verbosePrint("* appended value: %s\n" "* read value: %s\n" % (appended, read))
        self.assertEqual(appended, read, "Written and read values differ.")
Ejemplo n.º 33
0
    def test03_setitem(self):
        """Changing enumerated values using ``vlarray.__setitem__()``."""

        vlarr = self.h5file.create_vlarray("/", "test", self._atom(), title=self._getMethodName())
        vlarr.flavor = "python"

        appended = (self.valueInEnum, self.valueInEnum)
        vlarr.append(appended)

        written = [self.valueInEnum, self.valueOutOfEnum]
        vlarr[0] = written
        read = vlarr.read()
        common.verbosePrint("* written value: %s\n" "* read value: %s\n" % (written, read))
        self.assertEqual(written, read[0], "Written and read values differ.")
Ejemplo n.º 34
0
    def test(self):
        """Reading scalar arrays (see #98)."""

        arr = self.h5file.createArray('/', 'scalar_na', 1234)
        arr.flavor = 'numarray'

        self._reopen()

        arr = self.h5file.root.scalar_na

        common.verbosePrint("* %r == %r ?" % (arr.read(), array(1234)))
        self.assertTrue(all(arr.read() == array(1234)))
        common.verbosePrint("* %r == %r ?" % (arr[()], array(1234)))
        self.assertTrue(all(arr[()] == 1234))
Ejemplo n.º 35
0
    def testArrayFormats(self):
        """Check the checkFormats function.
        """

        common.verbosePrint( '\nTesting samples of formats description')
        formats = 'formats should be a list'
        self.assertRaises(TypeError, nra.nestedrecords._checkFormats,
            formats)
        # Formats must be a list of strings or sequences
        formats = [25,
            [['a5', 'a5'],['Float32', 'f4', 'f4']]]
        self.assertRaises(TypeError, nra.nestedrecords._checkFormats,
            formats)
        # If formats is OK checkFormats returns None
        self.assertEqual(nra.nestedrecords._checkFormats(self.formats),
            None)
Ejemplo n.º 36
0
    def test02_append(self):
        """Appending enumerated values using ``table.append()``."""

        tbl = self.h5file.createTable('/',
                                      'test',
                                      self._description(),
                                      title=self._getMethodName())

        appended = [(10, self.valueInEnum), (20, self.valueOutOfEnum)]

        tbl.append(appended)
        tbl.flush()
        tbl.flavor = 'python'
        read = tbl.read()
        common.verbosePrint("* appended value: %s\n"
                            "* read value: %s\n" % (appended, read))
        self.assertEqual(appended, read, "Written and read values differ.")
Ejemplo n.º 37
0
    def test05_where(self):
        """Searching enumerated data."""

        tbl = self.h5file.create_table("/", "test", self._description(), title=self._getMethodName())

        appended = [(10, self.valueInEnum), (20, self.valueInEnum), (30, self.valueOutOfEnum)]
        tbl.append(appended)
        tbl.flush()

        searched = [(row["rid"], row["rcolor"]) for row in tbl.where("rcolor == v", {"v": self.valueInEnum})]
        common.verbosePrint(
            "* ``valueInEnum``: %s\n"
            "* ``rcolor`` column: ``%s``\n"
            "* ``searched``: %s\n"
            "* Should look like: %s\n" % (self.valueInEnum, tbl.cols.rcolor, searched, appended[:-1])
        )
        self.assertEqual(searched, appended[:-1], "Search returned incorrect results.")
Ejemplo n.º 38
0
    def test03_setitem(self):
        """Changing enumerated values using ``vlarray.__setitem__()``."""

        vlarr = self.h5file.createVLArray('/',
                                          'test',
                                          self._atom(),
                                          title=self._getMethodName())
        vlarr.flavor = 'python'

        appended = (self.valueInEnum, self.valueInEnum)
        vlarr.append(appended)

        written = [self.valueInEnum, self.valueOutOfEnum]
        vlarr[0] = written
        read = vlarr.read()
        common.verbosePrint("* written value: %s\n"
                            "* read value: %s\n" % (written, read))
        self.assertEqual(written, read[0], "Written and read values differ.")
Ejemplo n.º 39
0
    def test03_setitem(self):
        """Changing enumerated values using ``table.__setitem__()``."""

        tbl = self.h5file.createTable('/',
                                      'test',
                                      self._description(),
                                      title=self._getMethodName())

        appended = [(10, self.valueInEnum), (20, self.valueInEnum)]
        tbl.append(appended)

        written = [(10, self.valueInEnum), (20, self.valueOutOfEnum)]
        tbl[:] = written
        tbl.flavor = 'python'
        read = tbl.read()
        common.verbosePrint("* written value: %s\n"
                            "* read value: %s\n" % (written, read))
        self.assertEqual(written, read, "Written and read values differ.")
Ejemplo n.º 40
0
    def create_indexes(self, colname, ncolname, extracolname):
        if not self.indexed:
            return
        try:
            kind = self.kind
            common.verbosePrint(f"* Indexing ``{colname}`` columns. Type: {kind}.")
            for acolname in [colname, ncolname, extracolname]:
                acolumn = self.table.colinstances[acolname]
                acolumn.create_index(
                    kind=self.kind, optlevel=self.optlevel,
                    _blocksizes=small_blocksizes, _testmode=True)

        except TypeError as te:
            if self.colNotIndexable_re.search(str(te)):
                raise SilentlySkipTest(
                    "Columns of this type can not be indexed.")
            raise
        except NotImplementedError:
            raise SilentlySkipTest(
                "Indexing columns of this type is not supported yet.")
Ejemplo n.º 41
0
    def test01_append(self):
        """Appending scalar elements of enumerated values."""

        vlarr = self.h5file.createVLArray('/',
                                          'test',
                                          self._atom(),
                                          title=self._getMethodName())
        vlarr.flavor = 'python'

        appended = [[
            self.valueInEnum,
        ], [self.valueInEnum, self.valueOutOfEnum]]

        vlarr.append(appended[0])
        vlarr.append(appended[1])
        vlarr.flush()
        read = vlarr.read()
        common.verbosePrint("* appended value: %s\n"
                            "* read value: %s\n" % (appended, read))
        self.assertEqual(appended, read, "Written and read values differ.")
Ejemplo n.º 42
0
    def test02_appendMD(self):
        """Appending multi-dimensional elements of enumerated values."""

        vlarr = self.h5file.createVLArray(
            '/', 'test', self._atom((2,)),
            title=self._getMethodName() )
        vlarr.flavor = 'python'

        appended = [
            [[self.valueInEnum, self.valueInEnum],],
            [[self.valueInEnum, self.valueOutOfEnum],
             [self.valueInEnum, self.valueInEnum]]]

        vlarr.append(appended[0])
        vlarr.append(appended[1])
        vlarr.flush()
        read = vlarr.read()
        common.verbosePrint(
            "* appended value: %s\n"
            "* read value: %s\n"
            % (appended, read) )
        self.assertEqual(appended, read, "Written and read values differ.")
Ejemplo n.º 43
0
    def testNamesUniqueness(self):
        """Check that names are unique at every level of the names list.
        """

        common.verbosePrint('\nTesting checkNamesUniqueness')
        foo = nriterators.checkNamesUniqueness
        badNames = ['info',
        ('info', [('name', ['first', 'second']),
                                ('coord', ['x', 'y', 'z'])])]
        self.assertRaises(ValueError, foo, badNames)
        badNames = ['position',
        ('info', [('coord', ['first', 'second']),
                                ('coord', ['x', 'y', 'z'])])]
        self.assertRaises(ValueError, foo, badNames)
        badNames = ['position',
        ('info', [('name', ['first', 'second']),
                                ('coord', ['x', 'x', 'z'])])]
        self.assertRaises(ValueError, foo, badNames)
        goodNames = ['position',
        ('info', [('info', ['first', 'second']),
                                ('coord', ['x', 'y', 'z'])])]
        self.assertEqual(foo(goodNames), None)
Ejemplo n.º 44
0
    def testArrayNames(self):
        """Check the checkNames function.
        """

        common.verbosePrint( '\nTesting samples of names description')
        names = 'names should be a list'
        self.assertRaises(TypeError, nra.nestedrecords._checkNames,
            names)
        # Names must be a list of strings or 2-tuples
        names = [25,
            ('info', [('name', ['first', 'second']),
                                ('coord', ['x', 'y', 'z'])])]
        self.assertRaises(TypeError, nra.nestedrecords._checkNames, names)

        # Names must be unique at any given level
        names = ['position',
            ('info', [('name', ['first', 'second']),
                                ('coord', ['x', 'y', 'y'])])]
        self.assertRaises(ValueError, nra.nestedrecords._checkNames, names)

        # If names is OK checkNames returns None
        self.assertEqual(nra.nestedrecords._checkNames(self.names), None)
Ejemplo n.º 45
0
    def testArrayDescr(self):
        """Check the checkDescr function.
        """

        common.verbosePrint( '\nTesting samples of descr description')
        # Descr must be a list of 2-tuples
        descr = 'some descr specification'
        self.assertRaises(TypeError, nra.nestedrecords._checkDescr, descr)

        # names in descr must be strings
        # formats must be strings or list of 2-tuples
        descr = [(25, 'Int64'),
            ('info', [('name', [('first','a5'), ('second','a5')]),
                   ('coord', [('x','Float32'), ('y', 'f4'), ('z', 'f4')])])]
        self.assertRaises(TypeError, nra.nestedrecords._checkDescr, descr)

        descr = [('25', 'position', 'Int64'),
            ('info', [('name', [('first','a5'), ('second','a5')]),
                   ('coord', [('x','Float32'), ('y', 'f4'), ('z', 'f4')])])]
        self.assertRaises(TypeError, nra.nestedrecords._checkDescr, descr)

        # If descr is OK checkDescr returns None
        self.assertEqual(nra.nestedrecords._checkDescr(self.descr), None)
Ejemplo n.º 46
0
    def testArrayStructure(self):
        """Check the isThereStructure function.
        """

        common.verbosePrint( '\nTesting array structure check function')
        common.verbosePrint( 'With descr description...')
        cse = \
            nra.nestedrecords._isThereStructure( None, self.descr,
            self.buffer)
        self.assertEqual(cse, None)

        common.verbosePrint( 'With formats description...')
        cse = \
            nra.nestedrecords._isThereStructure(self.formats, None,
            self.buffer)
        self.assertEqual(cse, None)

        common.verbosePrint( 'With no description...')
        self.assertRaises(NotImplementedError,
            nra.nestedrecords._isThereStructure, None, None, self.buffer)
        self.assertRaises(ValueError, nra.nestedrecords._isThereStructure,
            None, None, None)
Ejemplo n.º 47
0
    def testArrayStructure(self):
        """Check the isThereStructure function.
        """

        common.verbosePrint('\nTesting array structure check function')
        common.verbosePrint('With descr description...')
        cse = \
            nra.nestedrecords._isThereStructure( None, self.descr,
            self.buffer)
        self.assertEqual(cse, None)

        common.verbosePrint('With formats description...')
        cse = \
            nra.nestedrecords._isThereStructure(self.formats, None,
            self.buffer)
        self.assertEqual(cse, None)

        common.verbosePrint('With no description...')
        self.assertRaises(NotImplementedError,
                          nra.nestedrecords._isThereStructure, None, None,
                          self.buffer)
        self.assertRaises(ValueError, nra.nestedrecords._isThereStructure,
                          None, None, None)
Ejemplo n.º 48
0
    def testCreateNestedRecArray(self):
        """Check the array function.
        """

        flatarray = numarray.records.array(self.flat_buffer, self.flat_formats)
        common.verbosePrint("""\nTesting the creation of a nested """
                            """recarray: buffer + formats""")
        nra1 = nra.array(formats=self.formats, buffer=self.buffer)
        common.verbosePrint(
            """\nTesting the creation of a nested recarray: buffer + """
            """formats + names""")
        nra2 = nra.array(names=self.names,
                         formats=self.formats,
                         buffer=self.buffer)
        common.verbosePrint(
            """\nTesting the creation of a nested recarray: buffer + descr""")
        nra3 = nra.array(descr=self.descr, buffer=self.buffer)

        self.assertEqual(common.areArraysEqual(nra1, nra2), False)

        self.assert_(common.areArraysEqual(nra2, nra3))
Ejemplo n.º 49
0
    def testCreateNestedRecArray(self):
        """Check the array function.
        """

        flatarray = numarray.records.array(self.flat_buffer,
            self.flat_formats)
        common.verbosePrint( """\nTesting the creation of a nested """
            """recarray: buffer + formats""")
        nra1 = nra.array(formats=self.formats, buffer=self.buffer)
        common.verbosePrint(
            """\nTesting the creation of a nested recarray: buffer + """
            """formats + names""")
        nra2 = nra.array(names=self.names,
            formats=self.formats, buffer=self.buffer)
        common.verbosePrint(
            """\nTesting the creation of a nested recarray: buffer + descr""")
        nra3 = nra.array(descr=self.descr, buffer=self.buffer)

        self.assertEqual(common.areArraysEqual(nra1, nra2), False)

        self.assert_(common.areArraysEqual(nra2, nra3))
Ejemplo n.º 50
0
    def test_method(self):
        common.verbosePrint("* Condition is ``%s``." % cond)
        # Replace bitwise operators with their logical counterparts.
        pycond = cond
        for (ptop, pyop) in [('&', 'and'), ('|', 'or'), ('~', 'not')]:
            pycond = pycond.replace(ptop, pyop)
        pycond = compile(pycond, '<string>', 'eval')

        table = self.table
        self.create_indexes(colname, ncolname, 'c_idxextra')

        table_slice = dict(start=1, stop=table.nrows - 5, step=3)
        rownos, fvalues = None, None
        # Test that both simple and nested columns work as expected.
        # Knowing how the table is filled, results must be the same.
        for acolname in [colname, ncolname]:
            # First the reference Python version.
            pyrownos, pyfvalues, pyvars = [], [], condvars.copy()
            for row in table.iterrows(**table_slice):
                pyvars[colname] = row[acolname]
                pyvars['c_extra'] = row['c_extra']
                pyvars['c_idxextra'] = row['c_idxextra']
                try:
                    with warnings.catch_warnings():
                        warnings.filterwarnings(
                            'ignore',
                            'invalid value encountered in arc(cos|sin)',
                            RuntimeWarning)
                        isvalidrow = eval(pycond, func_info, pyvars)
                except TypeError:
                    raise SilentlySkipTest(
                        "The Python type does not support the operation.")
                if isvalidrow:
                    pyrownos.append(row.nrow)
                    pyfvalues.append(row[acolname])
            pyrownos = np.array(pyrownos)  # row numbers already sorted
            pyfvalues = np.array(pyfvalues, dtype=sctype)
            pyfvalues.sort()
            common.verbosePrint("* %d rows selected by Python from ``%s``."
                   % (len(pyrownos), acolname))
            if rownos is None:
                rownos = pyrownos  # initialise reference results
                fvalues = pyfvalues
            else:
                self.assertTrue(np.all(pyrownos == rownos))  # check
                self.assertTrue(np.all(pyfvalues == fvalues))

            # Then the in-kernel or indexed version.
            ptvars = condvars.copy()
            ptvars[colname] = table.colinstances[acolname]
            ptvars['c_extra'] = table.colinstances['c_extra']
            ptvars['c_idxextra'] = table.colinstances['c_idxextra']
            try:
                isidxq = table.will_query_use_indexing(cond, ptvars)
                # Query twice to trigger possible query result caching.
                ptrownos = [table.get_where_list(cond, condvars, sort=True,
                                                 **table_slice)
                            for _ in range(2)]
                ptfvalues = [
                    table.read_where(cond, condvars, field=acolname,
                                     **table_slice)
                    for _ in range(2)
                ]
            except TypeError as te:
                if self.condNotBoolean_re.search(str(te)):
                    raise SilentlySkipTest("The condition is not boolean.")
                raise
            except NotImplementedError:
                raise SilentlySkipTest(
                    "The PyTables type does not support the operation.")
            for ptfvals in ptfvalues:  # row numbers already sorted
                ptfvals.sort()
            common.verbosePrint("* %d rows selected by PyTables from ``%s``"
                   % (len(ptrownos[0]), acolname), nonl=True)
            common.verbosePrint("(indexing: %s)." % ["no", "yes"][bool(isidxq)])
            self.assertTrue(np.all(ptrownos[0] == rownos))
            self.assertTrue(np.all(ptfvalues[0] == fvalues))
            # The following test possible caching of query results.
            self.assertTrue(np.all(ptrownos[0] == ptrownos[1]))
            self.assertTrue(np.all(ptfvalues[0] == ptfvalues[1]))