feat: add app handler method, get_appdir()
This commit is contained in:
parent
4b9db13b8f
commit
94868bbaa9
4 changed files with 97 additions and 1 deletions
|
@ -15,11 +15,13 @@ from wuttjamaican import app
|
|||
from wuttjamaican.progress import ProgressBase
|
||||
from wuttjamaican.conf import WuttaConfig
|
||||
from wuttjamaican.util import UNSPECIFIED
|
||||
from wuttjamaican.testing import FileConfigTestCase
|
||||
|
||||
|
||||
class TestAppHandler(TestCase):
|
||||
class TestAppHandler(FileConfigTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.setup_files()
|
||||
self.config = WuttaConfig(appname='wuttatest')
|
||||
self.app = app.AppHandler(self.config)
|
||||
self.config.app = self.app
|
||||
|
@ -39,6 +41,40 @@ class TestAppHandler(TestCase):
|
|||
obj = self.app.load_object('wuttjamaican.util:UNSPECIFIED')
|
||||
self.assertIs(obj, UNSPECIFIED)
|
||||
|
||||
def test_get_appdir(self):
|
||||
|
||||
mockdir = self.mkdir('mockdir')
|
||||
|
||||
# default appdir
|
||||
with patch.object(sys, 'prefix', new=mockdir):
|
||||
|
||||
# default is returned by default
|
||||
appdir = self.app.get_appdir()
|
||||
self.assertEqual(appdir, os.path.join(mockdir, 'app'))
|
||||
|
||||
# but not if caller wants config only
|
||||
appdir = self.app.get_appdir(configured_only=True)
|
||||
self.assertIsNone(appdir)
|
||||
|
||||
# also, cannot create if appdir path not known
|
||||
self.assertRaises(ValueError, self.app.get_appdir, configured_only=True, create=True)
|
||||
|
||||
# configured appdir
|
||||
self.config.setdefault('wuttatest.appdir', mockdir)
|
||||
appdir = self.app.get_appdir()
|
||||
self.assertEqual(appdir, mockdir)
|
||||
|
||||
# appdir w/ subpath
|
||||
appdir = self.app.get_appdir('foo', 'bar')
|
||||
self.assertEqual(appdir, os.path.join(mockdir, 'foo', 'bar'))
|
||||
|
||||
# subpath is created
|
||||
self.assertEqual(len(os.listdir(mockdir)), 0)
|
||||
appdir = self.app.get_appdir('foo', 'bar', create=True)
|
||||
self.assertEqual(appdir, os.path.join(mockdir, 'foo', 'bar'))
|
||||
self.assertEqual(os.listdir(mockdir), ['foo'])
|
||||
self.assertEqual(os.listdir(os.path.join(mockdir, 'foo')), ['bar'])
|
||||
|
||||
def test_make_appdir(self):
|
||||
|
||||
# appdir is created, and 3 subfolders added by default
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue