Exemple #1
0
 def test_insertObjects(self):
     dbName = self.getOutputPath('images.sqlite')
     print ">>> test_insertObjects: dbName = '%s'" % dbName
     mapper = SqliteFlatMapper(dbName, globals())
     n = 10
     
     for i in range(n):
         img = Image()
         img.setLocation(i+1, 'images.stk')
         mapper.store(img)
         
     mapper.setProperty('samplingRate', '3.0')
     mapper.setProperty('defocusU', 1000)
     mapper.setProperty('defocusV', 1000)
     mapper.setProperty('defocusU', 2000) # Test update a property value
     mapper.deleteProperty('defocusV') # Test delete a property
     mapper.commit()
     self.assertEqual(1, mapper.db.getVersion())
     mapper.close()
     
     # Test that values where stored properly
     mapper2 = SqliteFlatMapper(dbName, globals())
     
     self.assertTrue(mapper2.hasProperty('samplingRate'))
     self.assertTrue(mapper2.hasProperty('defocusU'))
     self.assertFalse(mapper2.hasProperty('defocusV'))
     
     self.assertEqual(mapper2.getProperty('samplingRate'), '3.0')
     self.assertEqual(mapper2.getProperty('defocusU'), '2000')
Exemple #2
0
    def test_insertObjects(self):
        dbName = self.getOutputPath("images.sqlite")
        print ">>> test_insertObjects: dbName = '%s'" % dbName
        mapper = SqliteFlatMapper(dbName, globals())
        n = 10

        for i in range(n):
            img = Image()
            img.setLocation(i + 1, "images.stk")
            mapper.store(img)

        mapper.setProperty("samplingRate", "3.0")
        mapper.setProperty("defocusU", 1000)
        mapper.setProperty("defocusV", 1000)
        mapper.setProperty("defocusU", 2000)  # Test update a property value
        mapper.deleteProperty("defocusV")  # Test delete a property
        mapper.commit()
        mapper.close()

        # Test that values where stored properly
        mapper2 = SqliteFlatMapper(dbName, globals())

        self.assertTrue(mapper2.hasProperty("samplingRate"))
        self.assertTrue(mapper2.hasProperty("defocusU"))
        self.assertFalse(mapper2.hasProperty("defocusV"))

        self.assertEqual(mapper2.getProperty("samplingRate"), "3.0")
        self.assertEqual(mapper2.getProperty("defocusU"), "2000")
    def test_insertObjects(self):
        dbName = self.getOutputPath('images.sqlite')
        print ">>> test_insertObjects: dbName = '%s'" % dbName
        mapper = SqliteFlatMapper(dbName, globals())
        n = 10

        for i in range(n):
            img = Image()
            img.setLocation(i + 1, 'images.stk')
            mapper.store(img)

        mapper.setProperty('samplingRate', '3.0')
        mapper.setProperty('defocusU', 1000)
        mapper.setProperty('defocusV', 1000)
        mapper.setProperty('defocusU', 2000)  # Test update a property value
        mapper.deleteProperty('defocusV')  # Test delete a property
        mapper.commit()
        self.assertEqual(1, mapper.db.getVersion())
        mapper.close()

        # Test that values where stored properly
        mapper2 = SqliteFlatMapper(dbName, globals())

        self.assertTrue(mapper2.hasProperty('samplingRate'))
        self.assertTrue(mapper2.hasProperty('defocusU'))
        self.assertFalse(mapper2.hasProperty('defocusV'))

        self.assertEqual(mapper2.getProperty('samplingRate'), '3.0')
        self.assertEqual(mapper2.getProperty('defocusU'), '2000')
Exemple #4
0
    def test_insertObjects(self):
        dbName = self.getOutputPath('images.sqlite')
        print ">>> test_insertObjects: dbName = '%s'" % dbName
        mapper = SqliteFlatMapper(dbName, globals())
        self.assertEqual(0, mapper.count())
        self.assertEqual(0, mapper.maxId())
        n = 10

        for i in range(n):
            img = Image()
            img.setLocation(i + 1, 'images.stk')
            mapper.insert(img)

        self.assertEqual(n, mapper.count())
        self.assertEqual(n, mapper.maxId())

        # Store one more image with bigger id
        img = Image()
        bigId = 1000
        img.setLocation(bigId, 'images.stk')
        img.setObjId(bigId)
        mapper.insert(img)
        self.assertEqual(bigId, mapper.maxId())

        # Insert another image with None as id, it should take bigId + 1
        img.setLocation(bigId + 1, 'images.stk')
        img.setObjId(None)
        mapper.insert(img)
        self.assertEqual(bigId + 1, mapper.maxId())

        mapper.setProperty('samplingRate', '3.0')
        mapper.setProperty('defocusU', 1000)
        mapper.setProperty('defocusV', 1000)
        mapper.setProperty('defocusU', 2000)  # Test update a property value
        mapper.deleteProperty('defocusV')  # Test delete a property
        mapper.commit()
        self.assertEqual(1, mapper.db.getVersion())
        mapper.close()

        # Test that values where stored properly
        mapper2 = SqliteFlatMapper(dbName, globals())

        self.assertTrue(mapper2.hasProperty('samplingRate'))
        self.assertTrue(mapper2.hasProperty('defocusU'))
        self.assertFalse(mapper2.hasProperty('defocusV'))

        self.assertEqual(mapper2.getProperty('samplingRate'), '3.0')
        self.assertEqual(mapper2.getProperty('defocusU'), '2000')

        # Make sure that maxId() returns the proper value after loading db
        self.assertEqual(bigId + 1, mapper2.maxId())