Exemplo n.º 1
0
 def test_add_observations(self):
     """
     Tests whether multiple rows are added to the counts table.
     :return:
     """
     conn_object = BiomConnection()
     conn_object.create_tables()
     conn_object.add_summary(values=('banana', 1, 2))
     conn_object.add_sample(values=('Sample1', 'banana'))
     conn_object.add_taxon(values=[('Listeria', 'banana', 'Bacteria',
                                    'Firmicutes', 'Bacilli', 'Bacillales',
                                    'Listeriaceae', 'Listeria',
                                    'monocytogenes'),
                                   ('Listeria2', 'banana', 'Bacteria',
                                    'Firmicutes', 'Bacilli', 'Bacillales',
                                    'Listeriaceae', 'Listeria',
                                    'monocytogenes')])
     conn_object.add_observation(
         values=[('banana', 'Listeria', 'Sample1',
                  0.5), ('banana', 'Listeria2', 'Sample1', 0.75)])
     conn = psycopg2.connect(
         **{
             "host": "localhost",
             "database": "test",
             "user": "******",
             "password": "******"
         })
     cur = conn.cursor()
     cur.execute("SELECT count from counts;")
     result = cur.fetchall()
     self.assertEqual(len(result), 2)
     cur.close()
     conn.close()
     conn_object.delete_tables()
Exemplo n.º 2
0
 def test_add_taxon_missingvalues(self):
     """
     Tests whether a row is added to the taxonomy table,
     even when some assignments are unknown.
     :return:
     """
     conn_object = BiomConnection()
     conn_object.create_tables()
     conn_object.add_summary(values=('banana', 1, 2))
     conn_object.add_taxon(values=('Listeria', 'banana', 'Bacteria',
                                   'Firmicutes', 'Bacilli', None, None,
                                   None, None))
     conn = psycopg2.connect(
         **{
             "host": "localhost",
             "database": "test",
             "user": "******",
             "password": "******"
         })
     cur = conn.cursor()
     cur.execute("SELECT * from taxonomy;")
     result = cur.fetchall()
     # long format table of 5 * 6 observations
     self.assertEqual(result[0],
                      ('Listeria', 'banana', 'Bacteria', 'Firmicutes',
                       'Bacilli', None, None, None, None))
     cur.close()
     conn.close()
     conn_object.delete_tables()
Exemplo n.º 3
0
 def test_observation_error(self):
     """
     Tests if the query correctly reports an error
     when a taxon is not present in the taxonomy table.
     :return:
     """
     conn_object = BiomConnection()
     conn_object.create_tables()
     conn_object.add_summary(values=('banana', 1, 2))
     conn_object.add_sample(values=('Sample1', 'banana'))
     conn_object.add_taxon(values=('Listeria', 'banana', 'Bacteria',
                                   'Firmicutes', 'Bacilli', 'Bacillales',
                                   'Listeriaceae', 'Listeria',
                                   'monocytogenes'))
     self.assertRaises(
         psycopg2.Error,
         conn_object.add_observation(values=('banana', 'Streptococcus',
                                             'Sample1', 0.5)),
     )
     # long format table of 5 * 6 observations
     conn_object.delete_tables()