Esempio n. 1
0
def test_dict_iter_item():
    package_path = os.path.join(test_packages, 'dict_iter_item')
    test_file = os.path.join(package_path, 'example.py')

    string_output = io.StringIO()
    vm = VirtualMachine()
    vm.set_std_stream(vm_out=string_output)
    vm.run_python_file(test_file)
    vm.reset_std_stream()

    target = '1 2\n3 4\n'
    assert string_output.getvalue() == target
Esempio n. 2
0
def test_class_inheritance():
    package_path = os.path.join(test_packages, "class_inheritance")
    test_file = os.path.join(package_path, "example.py")

    string_output = io.StringIO()
    vm = VirtualMachine()
    vm.set_std_stream(vm_out=string_output)
    vm.run_python_file(test_file)
    vm.reset_std_stream()

    target = "-14\n"
    assert string_output.getvalue() == target
Esempio n. 3
0
def test_so_many_const_values_scenario():
    package_path = os.path.join(test_packages, 'so_many_const_values_scenario')
    test_file = os.path.join(package_path, 'example.py')

    string_output = io.StringIO()
    vm = VirtualMachine()
    vm.set_std_stream(vm_out=string_output)
    vm.run_python_file(test_file)
    vm.reset_std_stream()

    target = '1000\n324\n735\n'
    assert string_output.getvalue() == target
Esempio n. 4
0
def test_multi_layer_closure():
    package_path = os.path.join(test_packages, "multi_layer_closure")
    test_file = os.path.join(package_path, "example.py")

    string_output = io.StringIO()
    vm = VirtualMachine()
    vm.set_std_stream(vm_out=string_output)
    vm.run_python_file(test_file)
    vm.reset_std_stream()

    target = "[]\n[10]\n[10, 20]\n"
    assert string_output.getvalue() == target
Esempio n. 5
0
def test_global_variable_manipulation():
    package_path = os.path.join(test_packages, "global_variable_manipulation")
    test_file = os.path.join(package_path, "example.py")

    string_output = io.StringIO()
    vm = VirtualMachine()
    vm.set_std_stream(vm_out=string_output)
    vm.run_python_file(test_file)
    vm.reset_std_stream()

    target = list(map(str, [10, 100]))
    assert string_output.getvalue().split() == target
Esempio n. 6
0
def test_while_loop():
    package_path = os.path.join(test_packages, "while_loop")
    test_file = os.path.join(package_path, "example.py")

    string_output = io.StringIO()
    vm = VirtualMachine()
    vm.set_std_stream(vm_out=string_output)
    vm.run_python_file(test_file)
    vm.reset_std_stream()

    target = list(map(str, [0, 1, 3, 7, 15, 31, 63]))
    assert string_output.getvalue().split() == target
Esempio n. 7
0
def test_slice_usage_in_object():
    package_path = os.path.join(test_packages, "slice_usage_in_object")
    test_file = os.path.join(package_path, "example.py")

    string_output = io.StringIO()
    vm = VirtualMachine()
    vm.set_std_stream(vm_out=string_output)
    vm.run_python_file(test_file)
    vm.reset_std_stream()

    target = "[1, 4, 7]\n"
    assert string_output.getvalue() == target
Esempio n. 8
0
def test_import_self_defined_module():
    package_path = os.path.join(test_packages, "import_self_defined_module")
    test_file = os.path.join(package_path, "a.py")

    string_output = io.StringIO()
    vm = VirtualMachine()
    vm.set_std_stream(vm_out=string_output)
    vm.run_python_file(test_file)
    vm.reset_std_stream()

    target = "77\n"
    assert string_output.getvalue() == target