예제 #1
0
        # Test recovering from a runtime error during import
        nb = Notebook(base)
        write_file("mod5.py", "a = b")
        try:
            do_test("import mod5", "mod5.a", 1, nb=nb)
        except NameError, e:
            pass
        # the old and new files will have the same second-resolution timestamps
        cleanup_pyc()
        write_file("mod5.py", "a = 1")
        nb.reset_module_by_filename(os.path.join(base, "mod5.py"))
        do_test("import mod5", "mod5.a", 1, nb=nb)

        nb = Notebook(base)
        assert_equals(nb.file_for_absolute_path(os.path.dirname(base)), None)
        assert_equals(nb.file_for_absolute_path(base), None)
        assert_equals(
            nb.file_for_absolute_path(os.path.join(base, "mod1.py")).path,
            "mod1.py")
        assert_equals(
            nb.file_for_absolute_path(os.path.join(base, "package1")), None)
        assert_equals(
            nb.file_for_absolute_path(os.path.join(base, "package1/")), None)
        assert_equals(
            nb.file_for_absolute_path(os.path.join(base,
                                                   "package1/mod2.py")).path,
            "package1/mod2.py")

        # Simple test of isolation - if this was the same notebook, then
        # we'd need to reset_module_by_filename()
예제 #2
0
        # Test recovering from a runtime error during import
        nb = Notebook(base)
        write_file("mod5.py", "a = b")
        try:
            do_test("import mod5", "mod5.a", 1, nb=nb)
        except NameError, e:
            pass
        # the old and new files will have the same second-resolution timestamps
        cleanup_pyc()
        write_file("mod5.py", "a = 1")
        nb.reset_module_by_filename(os.path.join(base, "mod5.py"))
        do_test("import mod5", "mod5.a", 1, nb=nb)

        nb = Notebook(base)
        assert_equals(nb.file_for_absolute_path(os.path.dirname(base)), None)
        assert_equals(nb.file_for_absolute_path(base), None)
        assert_equals(nb.file_for_absolute_path(os.path.join(base, "mod1.py")).path, "mod1.py")
        assert_equals(nb.file_for_absolute_path(os.path.join(base, "package1")), None)
        assert_equals(nb.file_for_absolute_path(os.path.join(base, "package1/")), None)
        assert_equals(nb.file_for_absolute_path(os.path.join(base, "package1/mod2.py")).path, "package1/mod2.py")

        # Simple test of isolation - if this was the same notebook, then
        # we'd need to reset_module_by_filename()
        write_file("mod6.py", "import mod7\na = mod7.a");
        write_file("mod7.py", "a = 1")
        do_test("import mod6", "mod6.a", 1) # creates a new notebook
        cleanup_pyc()
        write_file("mod7.py", "a = 2")
        do_test("import mod6", "mod6.a", 2) # creates a different new notebook