Пример #1
0
    def test_new_module_package(self) -> None:
        cr = bahc.CodeRunner("# test", "/foo/__init__.py", [])
        package = cr.new_module()

        cr = bahc.CodeRunner("# test", "path", [], package=package)
        m = cr.new_module()

        assert isinstance(m, ModuleType)
        assert m.__dict__['__name__'].startswith('bokeh_app_')
        assert m.__dict__['__file__'] == abspath("path")
        assert m.__dict__['__package__'] == package.__dict__["__name__"]
Пример #2
0
 def test_run_restores_argv(self) -> None:
     old_argv = list(sys.argv)
     cr = bahc.CodeRunner("# test", "path", ["foo", 10])
     assert not cr.ran
     m = cr.new_module()
     cr.run(m, lambda: None)
     assert sys.argv == old_argv
Пример #3
0
 def test_run_fixups_argv(self):
     cr = bahc.CodeRunner("import sys; argv = list(sys.argv)", "path",
                          ["foo", 10])
     assert not cr.ran
     m = cr.new_module()
     cr.run(m, lambda: None)
     assert m.__dict__['argv'] == ["path", "foo", 10]
Пример #4
0
 def test_reset_run_errors_leaves_permanent_errors(self):
     cr = bahc.CodeRunner("This is a syntax error", "path", [])
     cr._failed = True
     cr.reset_run_errors()
     assert cr.failed is True
     assert cr.error is not None
     assert cr.error_detail is not None
Пример #5
0
 def test_new_module_resets_run_errors(self):
     cr = bahc.CodeRunner("# test", "path", [])
     cr._failed = True
     m = cr.new_module()
     assert isinstance(m, ModuleType)
     assert m.__dict__['__name__'].startswith('bk_script_')
     assert m.__dict__['__file__'] == abspath("path")
Пример #6
0
 def test_run_restores_path(self):
     old_path = list(sys.path)
     cr = bahc.CodeRunner("# test", "path", ["foo", 10])
     assert not cr.ran
     m = cr.new_module()
     cr.run(m, lambda: None)
     assert sys.path == old_path
Пример #7
0
 def test_run_fixups_path(self):
     cr = bahc.CodeRunner("import sys; path = list(sys.path)", "/dir/to/path", ["foo", 10])
     assert not cr.ran
     m = cr.new_module()
     cr.run(m, lambda: None)
     assert m.__dict__['path'][0] == dirname("/dir/to/path")
     assert m.__dict__['path'][1:] == sys.path
Пример #8
0
 def test_run_restores_cwd(self):
     old_cwd = os.getcwd()
     cr = bahc.CodeRunner("import os; os.chdir('/')", "path", ["foo", 10])
     assert not cr.ran
     m = cr.new_module()
     cr.run(m, lambda: None)
     assert os.getcwd() == old_cwd
Пример #9
0
 def test_new_module_initpy(self) -> None:
     cr = bahc.CodeRunner("# test", "/foo/__init__.py", [])
     m = cr.new_module()
     assert isinstance(m, ModuleType)
     assert m.__dict__['__name__'].startswith('bokeh_app_')
     assert m.__dict__['__file__'].endswith("__init__.py")
     assert m.__dict__['__package__'] == m.__dict__['__name__']
Пример #10
0
 def test_new_module_success(self) -> None:
     cr = bahc.CodeRunner("# test", "path", [])
     m = cr.new_module()
     assert isinstance(m, ModuleType)
     assert m.__dict__['__name__'].startswith('bokeh_app_')
     assert m.__dict__['__file__'] == abspath("path")
     assert m.__dict__['__package__'] is None
Пример #11
0
 def test_init(self):
     cr = bahc.CodeRunner("# test", "path", [])
     assert cr.failed is False
     assert cr.error is None
     assert cr.error_detail is None
     assert cr.ran is False
     assert cr.source == "# test"
     assert cr.path == "path"
Пример #12
0
 def test_reset_run_errors(self):
     cr = bahc.CodeRunner("# test", "path", [])
     cr._failed = True
     cr._error = "error"
     cr._error_detail = "detail"
     cr.reset_run_errors()
     assert cr.failed is False
     assert cr.error is None
     assert cr.error_detail is None
Пример #13
0
 def test_run_runs_post_check(self):
     cr = bahc.CodeRunner("# test", "path", [])
     m = cr.new_module()
     assert not cr.ran
     result = {}
     def post_check():
         result['ran'] = True
     cr.run(m, post_check)
     assert cr.ran
     assert result == dict(ran=True)
Пример #14
0
 def test_new_module_returns_None_for_permanent_errors(self):
     cr = bahc.CodeRunner("This is a syntax error", "path", [])
     assert cr.failed is True
     m = cr.new_module()
     assert m is None
Пример #15
0
 def test_new_module_success(self):
     cr = bahc.CodeRunner("# test", "path", [])
     m = cr.new_module()
     assert isinstance(m, ModuleType)
     assert m.__dict__['__name__'].startswith('bk_script_')
     assert m.__dict__['__file__'] == abspath("path")
Пример #16
0
 def test_syntax_error_init(self):
     cr = bahc.CodeRunner("This is a syntax error", "path", [])
     assert cr.failed is True
     assert "Invalid syntax in" in cr.error
     assert cr.error_detail is not None
Пример #17
0
 def test_run_sets_ran(self):
     cr = bahc.CodeRunner("# test", "path", [])
     m = cr.new_module()
     assert not cr.ran
     cr.run(m, lambda: None)
     assert cr.ran
Пример #18
0
 def test_doc(self) -> None:
     cr = bahc.CodeRunner("'''some docstring\n\nfoo bar'''", "path", [])
     assert cr.failed is False
     assert cr.doc == "some docstring\n\nfoo bar"
Пример #19
0
 def test_package_error_init(self) -> None:
     with pytest.raises(ValueError):
         bahc.CodeRunner("This is a syntax error", "/foo/__init__.py", [],
                         "package")