Example #1
0
    def test(self):
        here = os.getcwd()
        mypid = os.getpid()
        with open("split-test.txt", "w") as f:
            f.write("foobar")
        with splitbrain(self.conn):
            try:
                path = tempfile.mkdtemp()

                import email

                self.assertNotIn("stale", repr(email))

                os.chdir(path)
                hispid = os.getpid()
                self.assertNotEqual(mypid, hispid)
                here2 = os.getcwd()
                self.assertNotEqual(here, here2)
                self.assertFalse(os.path.exists("split-test.txt"))
                with open("split-test.txt", "w") as f:
                    f.write("spam")

                with localbrain():
                    self.assertEqual(os.getpid(), mypid)
                    with open("split-test.txt", "r") as f:
                        self.assertEqual(f.read(), "foobar")

                try:
                    def f():
                        g()
                    def g():
                        h()
                    def h():
                        open("crap.txt", "r")
                    f()
                except IOError:
                    with localbrain():
                        tbtext = "".join(traceback.format_exception(*sys.exc_info()))
                    # pdb.post_mortem(sys.exc_info()[2])
                    self.assertIn("f()", tbtext)
                    self.assertIn("g()", tbtext)
                    self.assertIn("h()", tbtext)
                else:
                    self.fail("This should have raised a IOError")

            finally:
                # we must move away from the tempdir to delete it (at least on windows)
                os.chdir("/")
                shutil.rmtree(path)

        self.assertIn("stale", repr(email))

        self.assertEqual(os.getpid(), mypid)
        self.assertEqual(os.getcwd(), here)

        os.remove("split-test.txt")
Example #2
0
with open("tmp.txt", "w") as f:
    f.write("foobar")

with splitbrain(c):
    pid2 = os.getpid()
    assert pid1 != pid2
    import email
    print(email)
    import os as os2
    pid3 = os2.getpid()
    assert pid2 == pid3

    assert not os.path.exists("tmp.txt")

    with localbrain():
        with open("tmp.txt", "r") as f:
            assert f.read() == "foobar"
        pid4 = os.getpid()
        assert pid4 == pid1

    try:
        open("tmp.txt", "r")
    except IOError as ex:
        #print(type(ex), repr(ex))
        with localbrain():
            x = ("".join(traceback.format_exception(*sys.exc_info())))
            print(len(x))
    else:
        assert False, "expected an IOError"
Example #3
0
    def test(self):
        here = os.getcwd()
        mypid = os.getpid()
        with open("split-test.txt", "w") as f:
            f.write("foobar")
        with splitbrain(self.conn):
            try:
                path = tempfile.mkdtemp()

                import email

                self.assertNotIn("stale", repr(email))

                os.chdir(path)
                hispid = os.getpid()
                self.assertNotEqual(mypid, hispid)
                here2 = os.getcwd()
                self.assertNotEqual(here, here2)
                self.assertFalse(os.path.exists("split-test.txt"))
                with open("split-test.txt", "w") as f:
                    f.write("spam")

                with localbrain():
                    self.assertEqual(os.getpid(), mypid)
                    with open("split-test.txt", "r") as f:
                        self.assertEqual(f.read(), "foobar")

                try:

                    def f():
                        g()

                    def g():
                        h()

                    def h():
                        open("crap.txt", "r")

                    f()
                except IOError:
                    with localbrain():
                        tbtext = "".join(
                            traceback.format_exception(*sys.exc_info()))
                    # pdb.post_mortem(sys.exc_info()[2])
                    self.assertIn("f()", tbtext)
                    self.assertIn("g()", tbtext)
                    self.assertIn("h()", tbtext)
                else:
                    self.fail("This should have raised a IOError")

            finally:
                # we must move away from the tempdir to delete it (at least on windows)
                os.chdir("/")
                shutil.rmtree(path)

        self.assertIn("stale", repr(email))

        self.assertEqual(os.getpid(), mypid)
        self.assertEqual(os.getcwd(), here)

        os.remove("split-test.txt")
Example #4
0
with open("tmp.txt", "w") as f:
    f.write("foobar")

with splitbrain(c):
    pid2 = os.getpid()
    assert pid1 != pid2
    import email
    print (email)
    import os as os2
    pid3 = os2.getpid()
    assert pid2 == pid3
    
    assert not os.path.exists("tmp.txt")
    
    with localbrain():
        with open("tmp.txt", "r") as f:
            assert f.read() == "foobar"
        pid4 = os.getpid()
        assert pid4 == pid1
    
    try:
        open("tmp.txt", "r")
    except IOError as ex:
        #print(type(ex), repr(ex))
        with localbrain():
            x = ("".join(traceback.format_exception(*sys.exc_info())))
            print(len(x))
    else:
        assert False, "expected an IOError"