示例#1
0
    def it_can_create_a_new_empty_directory(self):
        """Note: tests integration with filesystem"""
        # case: created if does not exist
        # ------------------------------
        if os.path.exists(DELETEME_DIR):
            shutil.rmtree(DELETEME_DIR)
        PhysPkg._clear_or_make_dir(FOOBAR_DIR)
        assert os.path.exists(FOOBAR_DIR)

        # case: re-created if exists
        # ------------------------------
        if os.path.exists(DELETEME_DIR):
            shutil.rmtree(DELETEME_DIR)
        os.makedirs(FOOBAR_DIR)
        with open(FOOBAR_FILEPATH, "w") as f:
            f.write("foobar file")
        PhysPkg._clear_or_make_dir(FOOBAR_DIR)
        assert os.path.exists(FOOBAR_DIR)
        assert not os.path.exists(FOOBAR_FILEPATH)

        # case: raises if dirpath is file
        # ------------------------------
        shutil.rmtree(DELETEME_DIR)
        os.makedirs(DELETEME_DIR)
        with open(FOOBAR_DIR, "w") as f:
            f.write("foobar file at FOOBAR_DIR path")
        with pytest.raises(ValueError):
            PhysPkg._clear_or_make_dir(FOOBAR_DIR)