from unittest import TestCase from unittest.mock import patch from pyjsparser import parse from jasinta import interpret class TestBasicAddition(TestCase): @patch("builtins.print") def test_interpret(self, mock_print): s = """var a=3; var b=1; var c=a+b; document.write(c);""" interpret(parse(s)) mock_print.assert_called_with(4) class TestAssignment(TestCase): @patch("builtins.print") def test_interpret(self, mock_print): s = """var a=1; var b=1; a+=b; b+=a; document.write(b);""" interpret(parse(s)) mock_print.assert_called_with(3)