Skip to content

Commit

Permalink
Merge pull request #1310 from scopatz/dblfree
Browse files Browse the repository at this point in the history
thx @scopatz !
Merging!
  • Loading branch information
Baaaaam committed Nov 14, 2016
2 parents f1b2546 + 7af8267 commit bb912eb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 267 deletions.
11 changes: 11 additions & 0 deletions cyclus/lib.pyx
Expand Up @@ -47,6 +47,7 @@ cdef class _Datum:
if self._free:
cpp_ptx = <cpp_cyclus.Datum*> self.ptx
del cpp_ptx
self.ptx = NULL

def add_val(self, const char* field, value, shape=None, dbtype=cpp_typesystem.BLOB):
"""Adds Datum value to current record as the corresponding cyclus data type.
Expand Down Expand Up @@ -104,8 +105,11 @@ cdef class _FullBackend:
def __dealloc__(self):
"""Full backend C++ destructor."""
# Note that we have to do it this way since self.ptx is void*
if self.ptx == NULL:
return
cdef cpp_cyclus.FullBackend * cpp_ptx = <cpp_cyclus.FullBackend *> self.ptx
del cpp_ptx
self.ptx = NULL

def query(self, table, conds=None):
"""Queries a database table.
Expand Down Expand Up @@ -204,8 +208,11 @@ cdef class _SqliteBack(_FullBackend):
def __dealloc__(self):
"""Full backend C++ destructor."""
# Note that we have to do it this way since self.ptx is void*
if self.ptx == NULL:
return
cdef cpp_cyclus.SqliteBack * cpp_ptx = <cpp_cyclus.SqliteBack *> self.ptx
del cpp_ptx
self.ptx = NULL

def flush(self):
"""Flushes the database to disk."""
Expand Down Expand Up @@ -238,8 +245,11 @@ cdef class _Hdf5Back(_FullBackend):
def __dealloc__(self):
"""Full backend C++ destructor."""
# Note that we have to do it this way since self.ptx is void*
if self.ptx == NULL:
return
cdef cpp_cyclus.Hdf5Back * cpp_ptx = <cpp_cyclus.Hdf5Back *> self.ptx
del cpp_ptx
self.ptx = NULL

def flush(self):
"""Flushes the database to disk."""
Expand Down Expand Up @@ -275,6 +285,7 @@ cdef class _Recorder:
# Note that we have to do it this way since self.ptx is void*
cdef cpp_cyclus.Recorder * cpp_ptx = <cpp_cyclus.Recorder *> self.ptx
del cpp_ptx
self.ptx = NULL

property dump_count:
"""The frequency of recording."""
Expand Down
264 changes: 0 additions & 264 deletions tests/input/libcyclus.xml

This file was deleted.

4 changes: 2 additions & 2 deletions tests/test_cycluslib.py
Expand Up @@ -37,11 +37,11 @@ def test_conds_ae(db, fname, backend):

@dbtest
def test_conds_comp(db, fname, backend):
conds = [('NucId', '==', 922350000), ('MassFrac', '>', 0.0072)]
conds = [('NucId', '==', 922350000), ('MassFrac', '<=', 0.0072)]
df = db.query("Compositions", conds)
assert_less(0, len(df))
for row in df['MassFrac']:
assert_less(0.0072, row)
assert_less(row, 0.00720000001)


if __name__ == "__main__":
Expand Down
7 changes: 6 additions & 1 deletion tests/tools.py
Expand Up @@ -32,6 +32,7 @@ def cleanfs(paths):
elif os.path.isdir(p):
shutil.rmtree(p)


def check_cmd(args, cwd, holdsrtn):
"""Runs a command in a subprocess and verifies that it executed properly.
"""
Expand All @@ -51,6 +52,7 @@ def check_cmd(args, cwd, holdsrtn):
holdsrtn[0] = rtn
assert_equal(rtn, 0)


@contextmanager
def clean_import(name, paths=None):
"""Imports and returns a module context manager and then removes
Expand All @@ -68,6 +70,7 @@ def clean_import(name, paths=None):
for newmod in newmods:
del sys.modules[newmod]


TESTNAME_RE = re.compile('(?:^|[\\b_\\.-])[Tt]est')

def modtests(mod):
Expand All @@ -82,6 +85,7 @@ def modtests(mod):
tests.append(test)
return tests


def dirtests(d):
"""Finds all of the test files in a directory."""
files = os.listdir(d)
Expand All @@ -94,6 +98,7 @@ def dirtests(d):
filenames.append(file[:-3])
return filenames


def skip_then_continue(msg=""):
"""A simple function to yield such that a test is marked as skipped
and we may continue on our merry way. A message may be optionally passed
Expand Down Expand Up @@ -143,7 +148,7 @@ def libcyclus_setup():
for fname, oname, _ in DBS:
if os.path.isfile(oname):
continue
safe_call(['cyclus', '-o' + oname, 'input/libcyclus.xml'])
safe_call(['cyclus', '-o' + oname, 'input/inventory.xml'])


def dbtest(f):
Expand Down

0 comments on commit bb912eb

Please sign in to comment.