def test_db_creation(self):
        ''' Tests if the db file created or not

        :return:
        '''

        dbm = DatabaseManagement('unittest.db', verbose=False)

        dbm.create_db()

        self.assertTrue(path.isfile('unittest.db'))
    def test_band_gap_search(self):
        ''' Tests if band gap search is successful or not

        :return:
        '''

        csvr = CSVReader('test_data.csv')

        properties = csvr.get_properties_from_csv()

        dbm = DatabaseManagement('unittest.db', verbose=False)

        dbm.create_db()
        dbm.create_table()

        dbm.append_multiple_rows(properties)

        table = dbm.search_by_band_gap(band_gap=2)

        self.assertEqual(len(table), 8)
    def test_table_creation(self):
        ''' Tests if the table was created successfully in the database

        :return:
        '''
        dbm = DatabaseManagement('unittest.db', verbose=False)

        dbm.create_table()

        conn = dbm.create_connection()

        c = dbm.create_cursor(conn)

        c.execute(
            '''SELECT name FROM sqlite_master WHERE type='table' AND name='material_properties' '''
        )

        self.assertTrue(c)

        dbm.close_connection(conn)
Exemple #4
0
def process_args():

    args = get_args()

    if args.read and args.store:

        csvr = CSVReader(args.read)

        properties = csvr.get_properties_from_csv()

        dbm = DatabaseManagement(db_name=args.store)

        dbm.create_db()
        dbm.create_table()

        dbm.append_multiple_rows(properties)

    elif args.database and (args.print_rows is not None):

        dbm = DatabaseManagement(db_name=args.database)

        dbm.print_info(num_rows=args.print_rows)

    elif args.database and args.material:

        dbm = DatabaseManagement(db_name=args.database)

        dbm.search_by_material(material_name=args.material)

    elif args.database and args.color:

        dbm = DatabaseManagement(db_name=args.database)

        dbm.search_by_color(color=args.color)

    elif args.database and args.band_gap:

        dbm = DatabaseManagement(db_name=args.database)

        dbm.search_by_band_gap(band_gap=args.band_gap, tol_perc=args.tol)

    elif (args.bg_min is not None) and (args.bg_max is not None):

        dbm = DatabaseManagement(db_name=args.database)

        dbm.search_by_band_gap_range(band_gap_min=args.bg_min, band_gap_max=args.bg_max)

    else:
        print('\n The arguemnts provided are not valid.')
    def test_multiple_append(self):
        ''' Tests if the multiple append is successful or not

        :return:
        '''

        csvr = CSVReader('test_data.csv')

        properties = csvr.get_properties_from_csv()

        dbm = DatabaseManagement('unittest.db', verbose=False)

        dbm.create_db()
        dbm.create_table()

        dbm.append_multiple_rows(properties)

        conn = dbm.create_connection()

        c = dbm.create_cursor(conn)

        c.execute('''SELECT * FROM material_properties''')

        table = c.fetchall()

        dbm.close_connection(conn)

        self.assertEqual(len(table), 100)