def test_check_if_empty_db_false(create_chromium_data):
    not_empty_table = Table(
        table='urls',
        path=create_chromium_data,
        browser=None,
        filename='anything',
        profile=None,
    )
    not_empty_table._connect()
    assert not_empty_table.check_if_db_empty() == False
Пример #2
0
def non_pytest_test_DatabaseLockedError(test_suite):
    for test_case in test_suite:
        db_file_path_uri_mode = f'file:{test_case.path}?mode=ro'
        conn = sqlite3.connect(f'{test_case.path}',
                               isolation_level='EXCLUSIVE')
        # conn.row_factory = sqlite3.Row'
        cur = conn.cursor()
        yield_records = cur.execute(f'SELECT * FROM {test_case.table}')
        pprint(list(yield_records))
        # with sqlite3.connect(f'{test_case.path}') as conn2:
        # 	conn
        table_obj = Table(*test_case)
        table_obj._connect()
def test_check_if_empty_db_true(create_chromium_data):
    with tempfile.TemporaryDirectory() as tmpdir:
        dbname = 'empty.sqlite'
        dbpath = str(Path(tmpdir, dbname))
        conn = sqlite3.connect(dbpath)
        conn.close()
        empty_ = Table(
            table='nonexistent_table',
            path=dbpath,
            browser=None,
            filename=dbname,
            profile=None,
        )
        empty_._connect()
        assert empty_.check_if_db_empty() == True
        empty_._connection.close()
def test_connect_FileNotFoundError(tests_root):
    invalid_path = str(Path(tests_root, 'invalid0', 'invalid1', 'invalid2'))
    table = Table(
        table='some_table',
        path=invalid_path,
        browser='mozilla',
        filename='anything',
        profile='test',
    )
    excep = table._connect()
    assert isinstance(excep, FileNotFoundError)