def test_mkdir_no_parents_file(BASE): p = PathPlus(BASE, "fileA") assert p.exists() # An exception is raised when the last path component is an existing # regular file, regardless of whether exist_ok is true or not. with pytest.raises(FileExistsError) as exc_info: p.mkdir() assert exc_info.value.errno == errno.EEXIST with pytest.raises(FileExistsError) as exc_info: p.mkdir(exist_ok=True) assert exc_info.value.errno == errno.EEXIST
def test_mkdir_exist_ok(BASE): p = PathPlus(BASE, "dirB") st_ctime_first = p.stat().st_ctime assert (p.exists()) assert (p.is_dir()) with pytest.raises(FileExistsError) as cm: p.mkdir() assert (cm.value.errno == errno.EEXIST) p.mkdir(exist_ok=True) assert (p.exists()) assert (p.stat().st_ctime == st_ctime_first)
def test_mkdir_exist_ok_with_parent(BASE): p = PathPlus(BASE, "dirC") assert p.exists() with pytest.raises(FileExistsError) as cm: p.mkdir() assert (cm.value.errno == errno.EEXIST) p = p / "newdirC" p.mkdir(parents=True) st_ctime_first = p.stat().st_ctime assert p.exists() with pytest.raises(FileExistsError) as cm: p.mkdir(parents=True) assert (cm.value.errno == errno.EEXIST) p.mkdir(parents=True, exist_ok=True) assert p.exists() assert (p.stat().st_ctime == st_ctime_first)
def test_mkdir_parents(BASE): # Creating a chain of directories. p = PathPlus(BASE, "newdirB", "newdirC") assert not (p.exists()) with pytest.raises(OSError) as cm: p.mkdir() assert (cm.value.errno == errno.ENOENT) p.mkdir(parents=True) assert (p.exists()) assert (p.is_dir()) with pytest.raises(OSError) as cm: p.mkdir(parents=True) assert (cm.value.errno == errno.EEXIST) # Test `mode` arg. mode = stat.S_IMODE(p.stat().st_mode) # Default mode. p = PathPlus(BASE, "newdirD", "newdirE") p.mkdir(0o555, parents=True) assert (p.exists()) assert (p.is_dir()) if os.name != "nt": # The directory's permissions follow the mode argument. assert (stat.S_IMODE(p.stat().st_mode) == 0o7555 & mode) # The parent's permissions follow the default process settings. assert (stat.S_IMODE(p.parent.stat().st_mode) == mode)
'', "The output should look similar to this:": ".. clearpage::\nThe output should look similar to this:", } notebooks = [ "Displaying_TIC", "Displaying_Multiple_IC", "Displaying_Mass_Spec", "Displaying_Detected_Peaks", "Display_User_Interaction", ] demo_rst_dir = PathPlus("doc-source/demo_rst").resolve() if not demo_rst_dir.is_dir(): demo_rst_dir.mkdir() images_dir = PathPlus("doc-source/examples/graphics").resolve() if not images_dir.is_dir(): images_dir.mkdir() for notebook in notebooks: # Convert the notebook to RST format markdown_content = PathPlus(f"demo/jupyter/{notebook}.ipynb").read_text() markdown_content = markdown_content.replace("<!---->", '|') (body, resources) = rst_exporter.from_notebook_node( nbformat.reads(markdown_content, as_version=4))