From efacd65041f6f4e0121348b2ede841329368416b Mon Sep 17 00:00:00 2001 From: Christopher Baklid Date: Sat, 2 Jun 2018 22:15:56 +0200 Subject: set dependency on rmq publish --- tests/test_snekbox.py | 80 ++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 39 deletions(-) (limited to 'tests/test_snekbox.py') diff --git a/tests/test_snekbox.py b/tests/test_snekbox.py index f22e25f..addcf5d 100644 --- a/tests/test_snekbox.py +++ b/tests/test_snekbox.py @@ -13,45 +13,47 @@ snek = Snekbox(nsjail_binary=nsjail) class SnekTests(unittest.TestCase): - def test_nsjail(self): - result = snek.python3('print("test")') - self.assertEquals(result.strip(), 'test') - - def test_memory_error(self): - code = ('x = "*"\n' - 'while True:\n' - ' x = x * 99\n') - - result = snek.python3(code) - self.assertEquals(result.strip(), 'MemoryError') - - def test_timeout(self): - code = ('x = "*"\n' - 'while True:\n' - ' try:\n' - ' x = x * 99\n' - ' except:\n' - ' continue\n') - - result = snek.python3(code) - self.assertEquals(result.strip(), 'timed out or memory limit exceeded') - - def test_kill(self): - code = ('import subprocess\n' - 'print(subprocess.check_output("kill -9 6", shell=True).decode())') - result = snek.python3(code) - if 'ModuleNotFoundError' in result.strip(): - self.assertIn('ModuleNotFoundError', result.strip()) - else: - self.assertIn('returned non-zero exit status 1.', result.strip()) + def test_nsjail(self): + result = snek.python3('print("test")') + self.assertEquals(result.strip(), 'test') + + def test_memory_error(self): + code = ('x = "*"\n' + 'while True:\n' + ' x = x * 99\n') + + result = snek.python3(code) + self.assertEquals(result.strip(), 'MemoryError') + + def test_timeout(self): + code = ('x = "*"\n' + 'while True:\n' + ' try:\n' + ' x = x * 99\n' + ' except:\n' + ' continue\n') + + result = snek.python3(code) + self.assertEquals(result.strip(), 'timed out or memory limit exceeded') + + def test_kill(self): + code = ('import subprocess\n' + 'print(subprocess.check_output("kill -9 6", shell=True).decode())') + result = snek.python3(code) + if 'ModuleNotFoundError' in result.strip(): + self.assertIn('ModuleNotFoundError', result.strip()) + else: + self.assertIn('returned non-zero exit status 1.', result.strip()) class RMQTests(unittest.TestCase): - def test_a_publish(self): - message = json.dumps({"snekid": "test", "message": "print('test')"}) - result = r.publish(message) - self.assertTrue(result) - - def test_b_consume(self): - result = r.consume(callback=snek.message_handler, queue='input', run_once=True) - self.assertEquals(result[2], b'{"snekid": "test", "message": "print(\'test\')"}') + @pytest.mark.dependency() + def test_a_publish(self): + message = json.dumps({"snekid": "test", "message": "print('test')"}) + result = r.publish(message) + self.assertTrue(result) + + @pytest.mark.dependency(depends=["RMQTests::test_a_publish"]) + def test_b_consume(self): + result = r.consume(callback=snek.message_handler, queue='input', run_once=True) + self.assertEquals(result[2], b'{"snekid": "test", "message": "print(\'test\')"}') -- cgit v1.2.3