diff --git a/headphones/softchroot_test.py b/headphones/softchroot_test.py index 847182c6..a7910692 100644 --- a/headphones/softchroot_test.py +++ b/headphones/softchroot_test.py @@ -1,7 +1,7 @@ import os import mock from headphones.unittestcompat import TestCase -from mock import MagicMock +#from mock import MagicMock from headphones.softchroot import SoftChroot from headphones.exceptions import SoftChrootError @@ -13,11 +13,10 @@ class SoftChrootTest(TestCase): cf = SoftChroot('/tmp/') self.assertIsInstance(cf, SoftChroot) - @mock.patch('headphones.config.ConfigObj', name='ConfigObjMock') - def test_create_on_file(self, config_obj_fabric_mock): - """ create SoftChroot on file, not a directory """ + def test_create_on_not_exists_dir(self): + """ create SoftChroot on non existent dir """ - path = os.path.join('tmp', 'notexist', 'asdf', '11', '12', 'np', 'itsssss') + path = os.path.join('/tmp', 'notexist', 'asdf', '11', '12', 'np', 'itsssss') with self.assertRaises(SoftChrootError) as exc: cf = SoftChroot(path) @@ -25,14 +24,19 @@ class SoftChrootTest(TestCase): self.assertRegexpMatches(str(exc.exception), r'No such directory') self.assertRegexpMatches(str(exc.exception), path) - @mock.patch('headphones.softchroot', name='SoftChrootMock') - def test_create_on_file(self, config_obj_fabric_mock): + @mock.patch('headphones.softchroot.os', wrap=os, name='OsMock') + def test_create_on_file(self, os_mock): """ create SoftChroot on file, not a directory """ - path = os.path.join('tmp', 'notexist', 'asdf', '11', '12', 'np', 'itsssss') + path = os.path.join('/tmp', 'notexist', 'asdf', '11', '12', 'np', 'itsssss') + + os_mock.path.sep = os.path.sep + os_mock.path.isdir.side_effect = lambda x: x != path with self.assertRaises(SoftChrootError) as exc: - cf = SoftChroot(path) + cf = SoftChroot(str(path)) + + self.assertTrue(os_mock.path.isdir.called) self.assertRegexpMatches(str(exc.exception), r'No such directory') self.assertRegexpMatches(str(exc.exception), path)