def create_db(path: str, github: bool=False) -> None: """ Create an empty OpenCL kernel database. Parameters ---------- path : str Path to database to create. github : bool, optional Add tables for GitHub metadata. """ path = os.path.expanduser(path) if os.path.exists(path): raise clgen.UserError("'{}' already exists".format(path)) db = sqlite3.connect(path) c = db.cursor() if github: script = clgen.sql_script('create-gh-samples-db') else: script = clgen.sql_script('create-samples-db') c.executescript(script) c.close() db.commit() db.close()
def run_script(path: str, script: str) -> None: """ Run an SQL script on a databse. Parameters ---------- path : str Path to database. script : str Name of SQL data script. """ db = sqlite3.connect(path) c = db.cursor() c.executescript(clgen.sql_script(script)) c.close() db.commit() db.close()
def test_sql_script(): with pytest.raises(clgen.InternalError): clgen.sql_script("This definitely isn't a real path") with pytest.raises(clgen.File404): clgen.sql_script("This definitely isn't a real path")
def test_sql_script(self): with self.assertRaises(clgen.InternalError): clgen.sql_script("This definitely isn't a real path") with self.assertRaises(clgen.File404): clgen.sql_script("This definitely isn't a real path")