This repository has been archived by the owner on Jun 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" Tests for ``yatsm.io.helpers`` | ||
""" | ||
import pytest | ||
|
||
from yatsm.io import helpers | ||
|
||
|
||
def test_mkdir_p_success(tmpdir): | ||
helpers.mkdir_p(tmpdir.join('test').strpath) | ||
|
||
|
||
def test_mkdir_p_succcess_exists(tmpdir): | ||
helpers.mkdir_p(tmpdir.join('test').strpath) | ||
helpers.mkdir_p(tmpdir.join('test').strpath) | ||
|
||
|
||
def test_mkdir_p_failure_permission(tmpdir): | ||
with pytest.raises(OSError): | ||
helpers.mkdir_p('/asdf') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" YATSM IO module | ||
TODO: include result file IO abstraction (issue #69) | ||
Contents: | ||
* ``helpers``: Collection of helper functions that ease common filesystem | ||
operations | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" Collection of helper functions that ease common filesystem operations | ||
""" | ||
import errno | ||
import os | ||
|
||
|
||
def mkdir_p(d): | ||
""" Make a directory, ignoring error if it exists (i.e., ``mkdir -p``) | ||
Args: | ||
d (str): directory path to create | ||
Raises: | ||
OSError: Raise OSError if cannot create directory for reasons other | ||
than it existing already (errno 13 "EEXIST") | ||
""" | ||
try: | ||
os.makedirs(d) | ||
except OSError as err: | ||
# File exists | ||
if err.errno == errno.EEXIST: | ||
pass | ||
else: | ||
raise err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters