コード例 #1
0
ファイル: testDataCategory.py プロジェクト: rcsb/py-mmcif
    def testGetValues(self):
        """Test case -  value getters"""
        try:
            dcU = DataCategory("A", self.__attributeList,
                               self.__rowListUnicode)
            aL = dcU.getAttributeList()
            logger.debug("Row length %r", dcU.getRowCount())
            for ii, v in enumerate(self.__testRowUnicode):
                at = aL[ii + 1]
                for j in range(0, dcU.getRowCount()):
                    logger.debug("ii %d j %d at %s val %r ", ii, j, at, v)
                    self.assertEqual(dcU.getValue(at, j), v)
                    self.assertEqual(dcU.getValueOrDefault(at, j, "mydefault"),
                                     v)
            #
            # negative indices are interpreted in the python manner
            self.assertEqual(dcU.getValueOrDefault("colOrd", -1, "default"), 9)

            self.assertRaises(IndexError, dcU.getValue, "colOrd",
                              dcU.getRowCount() + 1)
            self.assertRaises(ValueError, dcU.getValue, "badAtt", 0)
            #
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
コード例 #2
0
    def test_get_values(self, category_data):
        dcU = DataCategory('A', category_data['attributeList'],
                           category_data['rowListUnicode'])
        aL = dcU.getAttributeList()
        print("Row length %r " % dcU.getRowCount())
        for ii, v in enumerate(category_data['testRowUnicode']):
            at = aL[ii + 1]
            for j in range(0, dcU.getRowCount()):
                print("ii %d j %d at %s val %r " % (ii, j, at, v))
                assert dcU.getValue(at, j) == v
                assert dcU.getValueOrDefault(at, j, 'mydefault') == v
        #
        # negative indices are interpreted in the python manner
        assert dcU.getValueOrDefault('colOrd', -1, 'default') == 9

        with pytest.raises(IndexError):
            dcU.getValueOrDefault('colOrd', dcU.getRowCount() + 1, 0)
        with pytest.raises(ValueError):
            dcU.getValueOrDefault('badAtt', 0, 0)