def test_predicate_error(self): expected_msg = 'The function COMMON-LISP-USER::MISSING-FUNCTION is undefined' try: self.sut.predicate('(missing-function)') self.fail('exception should be raised!') except SconeError as e: assert_that(str(e), is_(expected_msg))
def setUp(self): assert_that(localhost, is_not(listen_port(5001))) self.cmd = '{0}/Server.py --Ice.Config={0}/Server.config'.format( SRC_DIR) ic = Ice.initialize() self.addCleanup(ic.destroy) str_proxy = 'scone -t:tcp -h localhost -p 5001' proxy = ic.stringToProxy(str_proxy) self.scone = Semantic.SconeServicePrx.uncheckedCast(proxy)
def test_new_is_a_FAIL(self): response = self.sut.sentence('(new-indv {Daniel} {elephant})') assert_that(response, is_('{Daniel}')) expected_msg = '{Daniel} cannot be a {bird}' try: response = self.sut.sentence('(new-is-a {Daniel} {bird})') self.fail('exception should be raised!') except SconeError as e: assert_that(str(e), is_(expected_msg))
def do_eval(self): actual = self.resolve_actual(self.actual) try: self.evaluated = True assert_that(actual, self.matcher, self._client_reason) except AssertionError as e: self._reason = u"{0} {1}".format(self.describe_actual(), to_text(e)) return False return True
def test_local_knowledge_error(self): test_dir = 'test/knowledge_error' self.server = Popen(self.cmd.split(), stderr=PIPE, cwd=test_dir) time.sleep(5) self.addCleanup(self.server.terminate) assert_that(localhost, is_not(listen_port(5001))) expected = b"Error loading 'scone-knowledge.d/martin.lisp'" actual = self.server.stderr.read() print(expected) print(actual.decode('utf-8')) self.assert_(expected in actual)
def start_server(self, cwd=None): pid_file = Path(cwd) / Path('.scone/server.pid') pid_file.unlink(missing_ok=True) assert_that(localhost, is_not(listen_port(self.port))) self.scone = SubProcess('scone-server', stdout=io.BytesIO(), stderr=io.BytesIO(), signal=signal.SIGINT, cwd=cwd) self.addSubProcessCleanup(self.scone) wait_that(localhost, listen_port(self.port)) self.sut = SconeClient() self.sut.sentence('(new-indv {checkpoint} {thing})')
def do_eval(self): tini = time.time() while 1: try: if time.time() - tini > self.timeout: return False assert_that(self.resolve_actual(self.actual), self.matcher, self._client_reason) self.log_status() return True except AssertionError: self.status = Status.SOFTFAIL time.sleep(self.delta)
def test_multi_sentence(self): sentences = ''' (new-indv {Maria} {tiger}) (new-indv {Oscar} {bat}) (new-indv {Felix} {monkey}) (is-x-a-y? {Maria} {lion}) (is-x-a-y? {Oscar} {mammal}) (is-x-a-y? {Julio} {bird}) ''' responses = self.sut.multi_sentence(sentences) expected = [ '{Maria}', '{Oscar}', '{Felix}', 'NO', 'YES', 'MAYBE', ] assert_that(responses, is_(expected))
def test_new_is_a_OK(self): response = self.sut.sentence('(new-indv {Carlos} {thing})') assert_that(response, is_('{Carlos}')) response = self.sut.sentence('(new-is-a {Carlos} {bird})') assert_that(response[:8], is_('{Is-A 0-'))
def test_new_indv(self): response = self.sut.sentence('(new-indv {Marta} {elephant})') assert_that(response, is_('{Marta}'))
def test_predicate_maybe(self): response = self.sut.predicate('(is-x-a-y? {broom} {air transport})') assert_that(response, is_('MAYBE'))
def test_predicate_no(self): response = self.sut.predicate('(is-x-a-y? {bird} {mammal})') assert_that(response, is_('NO'))
def test_predicate_redundant_blanks(self): response = self.sut.predicate( '\n\n\n(is-x-a-y? {bird} {animal})\n\n\n') assert_that(response, is_('YES'))
def test_checkpoint(self): response = self.sut.sentence('(new-indv {Mork} {mammal})') assert_that(response, is_('{Mork}')) response = self.sut.sentence('(checkpoint-new "/tmp/kkk.lisp")') assert_that(response, is_('NIL'))