Esempio n. 1
0
class FilesystemTest(object):
    TEST_HIERARCHY = {
        "a_file": "Nothing important.",
        "animals": {
            "elephant": "large",
            "gonzo": "unique",
            "mouse": "small"
        },
        "images": {
            "image1.gif": "",
            "image2.jpg": "",
            "image3.png": ""
        },
        "swedish": {
            "chef": {
                "bork": {
                    "bork": "bork!"
                }
            }
        },
    }

    def setup_method(self, method):
        self.d = d = Path(tempfile.mkdtemp())
        dict2dir(d, self.TEST_HIERARCHY)
        self.a_file = Path(d, "a_file")
        self.animals = Path(d, "animals")
        self.images = Path(d, "images")
        self.chef = Path(d, "swedish", "chef", "bork", "bork")
        if hasattr(self.d, "write_link"):
            self.link_to_chef_file = Path(d, "link_to_chef_file")
            self.link_to_chef_file.write_link(self.chef)
            self.link_to_images_dir = Path(d, "link_to_images_dir")
            self.link_to_images_dir.write_link(self.images)
            self.dead_link = self.d.child("dead_link")
            self.dead_link.write_link("nowhere")
        self.missing = Path(d, "MISSING")
        self.d.chdir()

    def teardown_method(self, method):
        d = self.d
        d.parent.chdir()  # Always need a valid curdir to avoid OSErrors.
        if dump:
            dump_path(d)
        if cleanup:
            d.rmtree()
            if d.exists():
                raise AssertionError("unable to delete temp dir %s" % d)
        else:
            print("Not deleting test directory", d)
Esempio n. 2
0
class FilesystemTest(object):
    TEST_HIERARCHY = {
        "a_file":  "Nothing important.",
        "animals": {
            "elephant":  "large",
            "gonzo":  "unique",
            "mouse":  "small"},
        "images": {
            "image1.gif": "",
            "image2.jpg": "",
            "image3.png": ""},
        "swedish": {
            "chef": {
                "bork": {
                    "bork": "bork!"}}},
    }

    def setup_method(self, method):
        self.d = d = Path(tempfile.mkdtemp())
        dict2dir(d, self.TEST_HIERARCHY)
        self.a_file = Path(d, "a_file")
        self.animals = Path(d, "animals")
        self.images = Path(d, "images")
        self.chef = Path(d, "swedish", "chef", "bork", "bork")
        if hasattr(self.d, "write_link"):
            self.link_to_chef_file = Path(d, "link_to_chef_file")
            self.link_to_chef_file.write_link(self.chef)
            self.link_to_images_dir = Path(d, "link_to_images_dir")
            self.link_to_images_dir.write_link(self.images)
            self.dead_link = self.d.child("dead_link")
            self.dead_link.write_link("nowhere")
        self.missing = Path(d, "MISSING")
        self.d.chdir()

    def teardown_method(self, method):
        d = self.d
        d.parent.chdir()  # Always need a valid curdir to avoid OSErrors.
        if dump:
            dump_path(d)
        if cleanup:
            d.rmtree()
            if d.exists():
                raise AssertionError("unable to delete temp dir %s" % d)
        else:
            print("Not deleting test directory", d)
Esempio n. 3
0
 def test_rmtree_broken_symlink(self):
     symlink = Path(self.d, "symlink")
     symlink.write_link("broken")
     assert symlink.lexists()
     symlink.rmtree()
     assert not symlink.lexists()
Esempio n. 4
0
 def test_rmtree_broken_symlink(self):
     symlink = Path(self.d, "symlink")
     symlink.write_link("broken")
     assert symlink.lexists()
     symlink.rmtree()
     assert not symlink.lexists()