-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tests for core.util Mock now a requirement
- Loading branch information
1 parent
db562c9
commit bd280aa
Showing
4 changed files
with
36 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ requirements: | |
- python-levenshtein | ||
- datreant | ||
- pytest | ||
- mock | ||
|
||
test: | ||
imports: | ||
|
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,33 @@ | ||
import mock | ||
import os | ||
import pytest | ||
|
||
import datreant.core as dtr | ||
|
||
|
||
class TestMakedirs(object): | ||
def test_makedirs(self, tmpdir): | ||
with tmpdir.as_cwd(): | ||
dtr.util.makedirs('this/should/exist') | ||
assert os.path.exists('this/should/exist') | ||
assert os.path.isdir('this/should/exist') | ||
|
||
def test_makedirs_exists(self, tmpdir): | ||
# try and make a dir twice | ||
with tmpdir.as_cwd(): | ||
os.mkdir('this/') | ||
dtr.util.makedirs('this/') | ||
assert os.path.exists('this/') | ||
assert os.path.isdir('this/') | ||
|
||
def test_makedirs_error_catch(self, tmpdir): | ||
# mock a disk full error | ||
# and make sure it gets propagated through properly | ||
with tmpdir.as_cwd(): | ||
with mock.patch('os.makedirs') as mp: | ||
mp.side_effect = OSError(os.errno.ENOSPC, 'Mock - disk full') | ||
# check the specific error code | ||
# ie check we don't mangle it enroute | ||
with pytest.raises(OSError) as error: | ||
dtr.util.makedirs('this/should/fail') | ||
assert error.errno == os.errno.ENOSPC |