Skip to content

Commit

Permalink
Add additional tests for missing roots
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Mar 11, 2015
1 parent a35c3bd commit e8d38d9
Showing 1 changed file with 45 additions and 32 deletions.
77 changes: 45 additions & 32 deletions mine/test/test_services.py
@@ -1,5 +1,5 @@
"""Unit tests for the `services` module."""
# pylint: disable=C0111
# pylint: disable=R0201,C0111

import pytest
from unittest.mock import patch, Mock
Expand All @@ -11,48 +11,61 @@
from mine.test.conftest import FILES


def test_find_dropbox(tmpdir):
"""Verify a settings file can be found in Dropbox."""
tmpdir.chdir()
_touch('Dropbox', 'mine.yml')
class TestFindRoot:

path = services.find_config_path(tmpdir.strpath)
@patch('os.listdir', Mock(return_value=[]))
@patch('os.getenv', Mock(return_value=True))
def test_ci_workaround_enabled(self):
root = services.find_root(top="mock/top")
assert "mock/top" == root

assert os.path.isfile(path)
@patch('os.listdir', Mock(return_value=[]))
@patch('os.getenv', Mock(return_value=False))
def test_ci_workaround_disabled(self):
with pytest.raises(EnvironmentError):
services.find_root(top="mock/top")


def test_find_dropbox_personal(tmpdir):
"""Verify a settings file can be found in Dropbox (Personal)."""
tmpdir.chdir()
_touch('Dropbox (Personal)', 'mine.yml')

path = services.find_config_path(tmpdir.strpath)

assert os.path.isfile(path)
class TestFindConfigPath:

def test_find_dropbox(self, tmpdir):
"""Verify a settings file can be found in Dropbox."""
tmpdir.chdir()
_touch('Dropbox', 'mine.yml')

@patch('mine.services.DEPTH', 2)
def test_find_depth(tmpdir):
"""Verify a settings file is not found below the maximum depth."""
tmpdir.chdir()
_touch('Dropbox', 'a', 'b', 'mine.yml')
path = services.find_config_path(tmpdir.strpath)

with pytest.raises(OSError):
services.find_config_path(tmpdir.strpath)
assert os.path.isfile(path)

def test_find_dropbox_personal(self, tmpdir):
"""Verify a settings file can be found in Dropbox (Personal)."""
tmpdir.chdir()
_touch('Dropbox (Personal)', 'mine.yml')

@patch('os.path.isdir', Mock(return_value=False))
def test_find_no_home():
"""Verify an error occurs when no home directory is found."""
with pytest.raises(EnvironmentError):
services.find_config_path()
path = services.find_config_path(tmpdir.strpath)

assert os.path.isfile(path)

def test_find_no_share():
"""Verify an error occurs when no service directory is found."""
with pytest.raises(EnvironmentError):
with patch('os.getenv', Mock(return_value=False)):
services.find_config_path(FILES)
@patch('mine.services.DEPTH', 2)
def test_find_depth(self, tmpdir):
"""Verify a settings file is not found below the maximum depth."""
tmpdir.chdir()
_touch('Dropbox', 'a', 'b', 'mine.yml')

with pytest.raises(OSError):
services.find_config_path(tmpdir.strpath)

@patch('os.path.isdir', Mock(return_value=False))
def test_find_no_home(self):
"""Verify an error occurs when no home directory is found."""
with pytest.raises(EnvironmentError):
services.find_config_path()

def test_find_no_share(self):
"""Verify an error occurs when no service directory is found."""
with pytest.raises(EnvironmentError):
with patch('os.getenv', Mock(return_value=False)):
services.find_config_path(FILES)


@patch('os.remove')
Expand Down

0 comments on commit e8d38d9

Please sign in to comment.