Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_rangetest(self):
range_2_3_test = RangeTest(observation=[2, 3])
one_model = ConstModel(2.5)
self.assertTrue(range_2_3_test.check_capabilities(one_model))
score = range_2_3_test.judge(one_model)
self.assertTrue(isinstance(score, BooleanScore))
self.assertEqual(score.score,True)
self.assertTrue(score.test is range_2_3_test)
self.assertTrue(score.model is one_model)
def test_SciUnit(self):
from sciunit.base import SciUnit
sciunitObj = SciUnit()
self.assertIsInstance(sciunitObj.properties, dict)
self.assertIsInstance(sciunitObj.dict_hash({'1':1, '2':2}), str)
self.assertIsInstance(sciunitObj._id, int)
self.assertIsInstance(sciunitObj.id, str)
sciunitObj.json(string=False)
self.assertIsInstance(sciunitObj._class, dict)
sciunitObj.testState = "testState"
print(sciunitObj._state(keys=["testState"]))
sciunitObj.unpicklable.append("testState")
self.assertFalse("testState" in sciunitObj.__getstate__())
def test_SciUnitEncoder(self):
from sciunit.base import SciUnitEncoder, SciUnit
encoderObj = SciUnitEncoder()
d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
self.assertIsInstance(encoderObj.default(df), dict)
npArr = np.ndarray(shape=(2,2), dtype=int)
self.assertIsInstance(encoderObj.default(npArr), list)
sciunitObj = SciUnit()
sciunitObj.testState = "testState"
self.assertIsInstance(encoderObj.default(sciunitObj), dict)
self.assertRaises(TypeError, encoderObj.default, "This is a string")
class MyClass:
pass
self.assertIsInstance(encoderObj.default(MyClass()), str)
def test_rangetest(self):
range_2_3_test = RangeTest(observation=[2, 3])
one_model = ConstModel(2.5)
self.assertTrue(range_2_3_test.check_capabilities(one_model))
score = range_2_3_test.judge(one_model)
self.assertTrue(isinstance(score, BooleanScore))
self.assertEqual(score.score,True)
self.assertTrue(score.test is range_2_3_test)
self.assertTrue(score.model is one_model)
def test_rangetest(self):
from sciunit.tests import RangeTest
range_2_3_test = RangeTest(observation=[2,3])
one_model = sciunit.models.ConstModel(2.5)
self.assertTrue(range_2_3_test.check_capabilities(one_model))
score = range_2_3_test.judge(one_model)
self.assertTrue(isinstance(score, sciunit.scores.BooleanScore))
self.assertEqual(score.score,True)
self.assertTrue(score.test is range_2_3_test)
self.assertTrue(score.model is one_model)
def test_rangetest(self):
from sciunit.tests import RangeTest
range_2_3_test = RangeTest(observation=[2,3])
one_model = sciunit.models.ConstModel(2.5)
self.assertTrue(range_2_3_test.check_capabilities(one_model))
score = range_2_3_test.judge(one_model)
self.assertTrue(isinstance(score, sciunit.scores.BooleanScore))
self.assertEqual(score.score,True)
self.assertTrue(score.test is range_2_3_test)
self.assertTrue(score.model is one_model)
def test_testsuite(self):
t1 = self.T([2,3])
t2 = self.T([5,6])
m1 = self.M(2,3)
m2 = self.M(5,6)
t = TestSuite([t1,t2])
t.judge([m1,m2])
t = TestSuite([t1,t2],skip_models=[m1],include_models=[m2])
t.judge([m1,m2])
def prep_models_and_tests(self):
from sciunit import TestSuite
t1 = self.T([2,3],name='test1')
t2 = self.T([5,6])
m1 = self.M(2,3)
m2 = self.M(5,6)
t = TestSuite("MySuite",[t1,t2])
return (t,t1,t2,m1,m2)
def test_testsuite_hooks(self):
t1 = self.T([2,3])
t1.hook_called = False
t2 = self.T([5,6])
m = self.M(2,3)
def f(test, tests, score, a=None):
self.assertEqual(score,True)
self.assertEqual(a,1)
t1.hook_called = True
ts = TestSuite([t1,t2],name='MySuite',
hooks={t1:
{'f':f,
'kwargs':{'a':1}}
})
ts.judge(m)
self.assertEqual(t1.hook_called,True)
def test_testsuite_set_verbose(self):
from sciunit import TestSuite
t1 = self.T([2,3])
t2 = self.T([5,6])
t = TestSuite("MySuite",[t1,t2])
t.set_verbose(True)
self.assertEqual(t1.verbose,True)
self.assertEqual(t2.verbose,True)