def test_build_with_empty_params(self): model = cqgi.CQModel(TESTSCRIPT) result = model.build() self.assertTrue(result.success) self.assertTrue(len(result.results) == 1) self.assertTrue(result.results[0].shape == "2.0|3.0|bar|1.0")
def test_describe_parameter_invalid_doesnt_fail_script(self): script = textwrap.dedent(""" a = 2.0 describe_parameter(a, 2 - 1 ) """) model = cqgi.CQModel(script) a_param = model.metadata.parameters["a"] self.assertTrue(a_param.name == "a")
def test_that_invalid_syntax_in_script_fails_immediately(self): badscript = textwrap.dedent(""" this doesn't even compile """) with self.assertRaises(Exception) as context: model = cqgi.CQModel(badscript) self.assertTrue("invalid syntax" in context.exception.args)
def test_build_with_debug(self): model = cqgi.CQModel(TEST_DEBUG_SCRIPT) result = model.build() debugItems = result.debugObjects self.assertTrue(len(debugItems) == 2) self.assertTrue(debugItems[0].shape == "bar") self.assertTrue(debugItems[0].options == {"color": "yellow"}) self.assertTrue(debugItems[1].shape == 2.0) self.assertTrue(debugItems[1].options == {})
def test_build_with_exception(self): badscript = textwrap.dedent(""" raise ValueError("ERROR") """) model = cqgi.CQModel(badscript) result = model.build({}) self.assertFalse(result.success) self.assertIsNotNone(result.exception) self.assertTrue(result.exception.args[0] == "ERROR")
def test_describe_parameters(self): script = textwrap.dedent(""" a = 2.0 describe_parameter(a,'FirstLetter') """) model = cqgi.CQModel(script) a_param = model.metadata.parameters["a"] self.assertTrue(a_param.default_value == 2.0) self.assertTrue(a_param.desc == "FirstLetter") self.assertTrue(a_param.varType == cqgi.NumberParameterType)
def test_that_invalid_syntax_in_script_fails_immediately(self): badscript = textwrap.dedent(""" this doesn't even compile """) exception = None try: cqgi.CQModel(badscript) except Exception as e: exception = e self.assertIsInstance(exception, SyntaxError)
def test_that_two_results_are_returned(self): script = textwrap.dedent(""" h = 1 show_object(h) h = 2 show_object(h) """) model = cqgi.CQModel(script) result = model.build({}) self.assertEqual(2, len(result.results)) self.assertEqual(1, result.results[0].shape) self.assertEqual(2, result.results[1].shape)
def test_build_with_different_params(self): model = cqgi.CQModel(TESTSCRIPT) result = model.build({"height": 3.0}) self.assertTrue(result.results[0].shape == "3.0|3.0|bar|1.0")
def test_parser(self): model = cqgi.CQModel(TESTSCRIPT) metadata = model.metadata self.assertEqual(set(metadata.parameters.keys()), {"height", "width", "a", "b", "foo"})
def test_parser(self): model = cqgi.CQModel(TESTSCRIPT) metadata = model.metadata self.assertEqual(set(metadata.parameters.keys()), {'height', 'width', 'a', 'b', 'foo'})