def test_db_to_dict(self): tmpdir = tempfile.mkdtemp() dfile = os.path.join(tmpdir, 'junk.db') recorder = DBCaseRecorder(dfile) # create some Cases where some are missing a variable outputs = ['comp1.z', 'comp2.z'] inputs = ['comp1.x', 'comp1.y', 'comp1.y2'] recorder.register(self, inputs, outputs) for i in range(10): inputs = [i, i*2, i*3] outputs = [i*i, float('NaN')] recorder.record(self, inputs, outputs, None, '', '') varnames = ['comp1.x', 'comp1.y', 'comp1.y2'] varinfo = case_db_to_dict(dfile, varnames) self.assertEqual(len(varinfo), 3) # each var list should have 10 data values in it for lst in varinfo.values(): self.assertEqual(len(lst), 10) # now use caseiter_to_dict to grab the same data varinfo = caseiter_to_dict(recorder.get_iterator(), varnames) # each var list should have 10 data values in it for lst in varinfo.values(): self.assertEqual(len(lst), 10) try: shutil.rmtree(tmpdir, onerror=onerror) except OSError: logging.error("problem removing directory %s", tmpdir)
def test_db_to_dict(self): tmpdir = tempfile.mkdtemp() dfile = os.path.join(tmpdir, 'junk.db') recorder = DBCaseRecorder(dfile) # create some Cases where some are missing a variable outputs = ['comp1.z', 'comp2.z'] inputs = ['comp1.x', 'comp1.y', 'comp1.y2'] recorder.register(self, inputs, outputs) for i in range(10): inputs = [i, i * 2, i * 3] outputs = [i * i, float('NaN')] recorder.record(self, inputs, outputs, None, '', '') varnames = ['comp1.x', 'comp1.y', 'comp1.y2'] varinfo = case_db_to_dict(dfile, varnames) self.assertEqual(len(varinfo), 3) # each var list should have 10 data values in it for lst in varinfo.values(): self.assertEqual(len(lst), 10) # now use caseiter_to_dict to grab the same data varinfo = caseiter_to_dict(recorder.get_iterator(), varnames) # each var list should have 10 data values in it for lst in varinfo.values(): self.assertEqual(len(lst), 10) try: shutil.rmtree(tmpdir, onerror=onerror) except OSError: logging.error("problem removing directory %s", tmpdir)
def test_caseiter_to_dict_with_errors(self): dct = caseiter_to_dict(self.caseiter, self.varnames, include_errors=True) self.assertEqual(len(dct), 3) for name,value in dct.items(): self.assertEqual(len(value), 20) if name == 'comp2.normal': self.assertTrue(isinstance(value[0], NormalDistribution)) else: self.assertTrue(isinstance(value[0], float))
def test_caseiter_to_dict(self): dct = caseiter_to_dict(self.caseiter, self.varnames) self.assertEqual(len(dct), 3) for name, value in dct.items(): self.assertEqual(len(value), 20) if name == 'comp2.normal': self.assertTrue(isinstance(value[0], NormalDistribution)) else: self.assertTrue(isinstance(value[0], float))
def test_db_to_dict(self): tmpdir = tempfile.mkdtemp() dfile = os.path.join(tmpdir, 'junk.db') recorder = DBCaseRecorder(dfile) # create some Cases where some are missing a variable outputs = ['comp1.z', 'comp2.z'] cases = [] for i in range(10): if i > 1: msg = '' else: msg = 'an error occurred' if i < 5: inputs = [('comp1.x', i), ('comp1.y', i * 2), ('comp1.y2', i * 3)] else: inputs = [('comp1.x', i), ('comp1.y', i * 2)] recorder.record(Case(inputs=inputs, outputs=outputs, msg=msg)) varnames = ['comp1.x', 'comp1.y', 'comp1.y2'] varinfo = case_db_to_dict(dfile, varnames) self.assertEqual(len(varinfo), 3) # each var list should have 3 data values in it (5 with the required variables minus # 2 with errors for name, lst in varinfo.items(): self.assertEqual(len(lst), 3) # now use caseiter_to_dict to grab the same data varinfo = caseiter_to_dict(recorder.get_iterator(), varnames) # each var list should have 3 data values in it (5 with the required variables minus # 2 with errors for name, lst in varinfo.items(): self.assertEqual(len(lst), 3) try: shutil.rmtree(tmpdir) except OSError: logging.error("problem removing directory %s" % tmpdir)
def test_db_to_dict(self): tmpdir = tempfile.mkdtemp() dfile = os.path.join(tmpdir, 'junk.db') recorder = DBCaseRecorder(dfile) # create some Cases where some are missing a variable outputs = ['comp1.z', 'comp2.z'] cases = [] for i in range(10): if i>1: msg = '' else: msg = 'an error occurred' if i<5: inputs = [('comp1.x', i), ('comp1.y', i*2), ('comp1.y2', i*3)] else: inputs = [('comp1.x', i), ('comp1.y', i*2)] recorder.record(Case(inputs=inputs, outputs=outputs, msg=msg)) varnames = ['comp1.x','comp1.y','comp1.y2'] varinfo = case_db_to_dict(dfile, varnames) self.assertEqual(len(varinfo), 3) # each var list should have 3 data values in it (5 with the required variables minus # 2 with errors for name,lst in varinfo.items(): self.assertEqual(len(lst), 3) # now use caseiter_to_dict to grab the same data varinfo = caseiter_to_dict(recorder.get_iterator(), varnames) # each var list should have 3 data values in it (5 with the required variables minus # 2 with errors for name,lst in varinfo.items(): self.assertEqual(len(lst), 3) try: shutil.rmtree(tmpdir) except OSError: logging.error("problem removing directory %s" % tmpdir)