def test_csv2lite3(self): """test csv2lite with id""" c = os.path.join(self.data_dir, "Geocode.csv") dslw.csv2lite(self.conn, c, add_id=True) self.assertTrue("geocode" in self.conn.get_tables()) ios = "SELECT id FROM geocode" rows = self.cur.execute(ios).fetchall() self.assertEqual([r[0] for r in rows], [1, 2, 3, 4])
def test_csv2lite1(self): """test csv2lite with participants.csv no id""" c = os.path.join(self.data_dir, "participants.csv") # NOTE: use csv name for table name; 'id' field already exists dslw.csv2lite(self.conn, c) # add_id=False) self.assertTrue("participants" in self.conn.get_tables()) ios = "SELECT * FROM participants WHERE os LIKE 'ios%'" n = len(self.cur.execute(ios).fetchall()) self.assertEqual(n, 44)
def test_csv2lite2(self): """test csv2lite with leading-zeros geocode""" c = os.path.join(self.data_dir, "Geocode.csv") # Note: don't use csv name for table name dslw.csv2lite(self.conn, c, "permits", force_text="Geocode") self.assertTrue("permits" in self.conn.get_tables()) ios = "SELECT geocode FROM permits" rows = self.cur.execute(ios).fetchall() # All records (4) are returned self.assertEqual(len(rows), 4) # All geocodes are unicode self.assertTrue(all([type(r[0]) is unicode for r in rows])) # All geocodes start with zero self.assertTrue(all([r[0].startswith("0") for r in rows]))