Skip to content

Commit

Permalink
Add tests for core.util (#138)
Browse files Browse the repository at this point in the history
* Add tests for core.util

Mock now a requirement
  • Loading branch information
richardjgowers authored and kain88-de committed Mar 15, 2017
1 parent db562c9 commit bd280aa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ branches:
# install python dependencies
install:
- pip install codecov
- pip install mock
- pip install pytest-cov
- pip install pytest-pep8
- pip install numpy
Expand Down
1 change: 1 addition & 0 deletions conda/datreant.core/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ requirements:
- python-levenshtein
- datreant
- pytest
- mock

test:
imports:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
scripts=[],
license='BSD',
long_description=open('README.rst').read(),
tests_require = ['numpy', 'pytest'],
tests_require = ['numpy', 'pytest', 'mock'],
install_requires=['asciitree', 'pathlib2', 'scandir', 'six', 'fuzzywuzzy']
)
33 changes: 33 additions & 0 deletions src/datreant/core/tests/test_util.py
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

0 comments on commit bd280aa

Please sign in to comment.