summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSridhar Ratnakumar <github@srid.name>2014-04-21 15:50:41 -0700
committerSridhar Ratnakumar <github@srid.name>2014-04-21 15:50:41 -0700
commita163283dc5ca4bb7a110803dc840e05967a88cd3 (patch)
tree3ffd8f9ee02ed50329711f9dd12be67be2f4bd30
parentd7ad27f4082492c0dc4c379502a568e097f2262b (diff)
parentebd443e78d3df99d98d001707786e561fa827b68 (diff)
downloadappdirs-a163283dc5ca4bb7a110803dc840e05967a88cd3.tar.gz
Merge pull request #35 from bdrung/master
Improve tests
-rw-r--r--appdirs.py57
-rw-r--r--setup.py46
-rw-r--r--test/test_api.py39
3 files changed, 66 insertions, 76 deletions
diff --git a/appdirs.py b/appdirs.py
index 4221945..f7750dd 100644
--- a/appdirs.py
+++ b/appdirs.py
@@ -26,7 +26,6 @@ if PY3:
unicode = str
-
def user_data_dir(appname=None, appauthor=None, version=None, roaming=False):
r"""Return full path to the user-specific data dir for this application.
@@ -122,12 +121,12 @@ def site_data_dir(appname=None, appauthor=None, version=None, multipath=False):
# XDG default for $XDG_DATA_DIRS
# only first, if multipath is False
path = os.getenv('XDG_DATA_DIRS',
- os.pathsep.join(['/usr/local/share', '/usr/share']))
- pathlist = [ os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep) ]
+ os.pathsep.join(['/usr/local/share', '/usr/share']))
+ pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)]
if appname:
if version:
appname = os.path.join(appname, version)
- pathlist = [ os.sep.join([x, appname]) for x in pathlist ]
+ pathlist = [os.sep.join([x, appname]) for x in pathlist]
if multipath:
path = os.pathsep.join(pathlist)
@@ -168,7 +167,7 @@ def user_config_dir(appname=None, appauthor=None, version=None, roaming=False):
For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME.
That means, by deafult "~/.config/<AppName>".
"""
- if sys.platform in [ "win32", "darwin" ]:
+ if sys.platform in ["win32", "darwin"]:
path = user_data_dir(appname, appauthor, None, roaming)
else:
path = os.getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config"))
@@ -208,7 +207,7 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False)
WARNING: Do not use this on Windows. See the Vista-Fail note above for why.
"""
- if sys.platform in [ "win32", "darwin" ]:
+ if sys.platform in ["win32", "darwin"]:
path = site_data_dir(appname, appauthor)
if appname and version:
path = os.path.join(path, version)
@@ -216,11 +215,11 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False)
# XDG default for $XDG_CONFIG_DIRS
# only first, if multipath is False
path = os.getenv('XDG_CONFIG_DIRS', '/etc/xdg')
- pathlist = [ os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep) ]
+ pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)]
if appname:
if version:
appname = os.path.join(appname, version)
- pathlist = [ os.sep.join([x, appname]) for x in pathlist ]
+ pathlist = [os.sep.join([x, appname]) for x in pathlist]
if multipath:
path = os.pathsep.join(pathlist)
@@ -228,6 +227,7 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False)
path = pathlist[0]
return path
+
def user_cache_dir(appname=None, appauthor=None, version=None, opinion=True):
r"""Return full path to the user-specific cache dir for this application.
@@ -280,6 +280,7 @@ def user_cache_dir(appname=None, appauthor=None, version=None, opinion=True):
path = os.path.join(path, version)
return path
+
def user_log_dir(appname=None, appauthor=None, version=None, opinion=True):
r"""Return full path to the user-specific log dir for this application.
@@ -316,11 +317,13 @@ def user_log_dir(appname=None, appauthor=None, version=None, opinion=True):
os.path.expanduser('~/Library/Logs'),
appname)
elif sys.platform == "win32":
- path = user_data_dir(appname, appauthor, version); version=False
+ path = user_data_dir(appname, appauthor, version)
+ version = False
if opinion:
path = os.path.join(path, "Logs")
else:
- path = user_cache_dir(appname, appauthor, version); version=False
+ path = user_cache_dir(appname, appauthor, version)
+ version = False
if opinion:
path = os.path.join(path, "log")
if appname and version:
@@ -330,39 +333,43 @@ def user_log_dir(appname=None, appauthor=None, version=None, opinion=True):
class AppDirs(object):
"""Convenience wrapper for getting application dirs."""
- def __init__(self, appname, appauthor=None, version=None,
- roaming=False, multipath=False):
+ def __init__(self, appname, appauthor=None, version=None, roaming=False,
+ multipath=False):
self.appname = appname
self.appauthor = appauthor
self.version = version
self.roaming = roaming
self.multipath = multipath
+
@property
def user_data_dir(self):
return user_data_dir(self.appname, self.appauthor,
- version=self.version, roaming=self.roaming)
+ version=self.version, roaming=self.roaming)
+
@property
def site_data_dir(self):
return site_data_dir(self.appname, self.appauthor,
- version=self.version, multipath=self.multipath)
+ version=self.version, multipath=self.multipath)
+
@property
def user_config_dir(self):
return user_config_dir(self.appname, self.appauthor,
- version=self.version, roaming=self.roaming)
+ version=self.version, roaming=self.roaming)
+
@property
def site_config_dir(self):
return site_data_dir(self.appname, self.appauthor,
- version=self.version, multipath=self.multipath)
+ version=self.version, multipath=self.multipath)
+
@property
def user_cache_dir(self):
return user_cache_dir(self.appname, self.appauthor,
- version=self.version)
+ version=self.version)
+
@property
def user_log_dir(self):
return user_log_dir(self.appname, self.appauthor,
- version=self.version)
-
-
+ version=self.version)
#---- internal support stuff
@@ -380,11 +387,14 @@ def _get_win_folder_from_registry(csidl_name):
"CSIDL_LOCAL_APPDATA": "Local AppData",
}[csidl_name]
- key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
- r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
+ key = _winreg.OpenKey(
+ _winreg.HKEY_CURRENT_USER,
+ r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
+ )
dir, type = _winreg.QueryValueEx(key, shell_folder_name)
return dir
+
def _get_win_folder_with_pywin32(csidl_name):
from win32com.shell import shellcon, shell
dir = shell.SHGetFolderPath(0, getattr(shellcon, csidl_name), 0, 0)
@@ -411,6 +421,7 @@ def _get_win_folder_with_pywin32(csidl_name):
pass
return dir
+
def _get_win_folder_with_ctypes(csidl_name):
import ctypes
@@ -449,7 +460,6 @@ if sys.platform == "win32":
_get_win_folder = _get_win_folder_from_registry
-
#---- self test code
if __name__ == "__main__":
@@ -474,4 +484,3 @@ if __name__ == "__main__":
dirs = AppDirs(appname)
for prop in props:
print("%s: %s" % (prop, getattr(dirs, prop)))
-
diff --git a/setup.py b/setup.py
index a787d65..ccd1e72 100644
--- a/setup.py
+++ b/setup.py
@@ -2,43 +2,12 @@
import sys
import os
import os.path
-from distutils.core import setup, Command
+from setuptools import setup
import appdirs
-requires_list = []
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
-else:
- if sys.version_info <= (2, 6):
- requires_list.append("unittest2")
-
-
-class RunTests(Command):
- """New setup.py command to run all tests for the package.
- """
- description = "run all tests for the package"
-
- user_options = []
-
- def initialize_options(self):
- pass
-
- def finalize_options(self):
- pass
-
- def run(self):
- test_modules = ["test.%s" % filename.replace('.py', '')
- for filename in os.listdir('test')
- if filename.endswith('.py') and filename.startswith('test_')]
- for mod in test_modules:
- __import__(mod)
-
- suite = unittest.TestSuite()
- for mod in [sys.modules[modname] for modname in test_modules]:
- suite.addTest(unittest.TestLoader().loadTestsFromModule(mod))
- unittest.TextTestRunner(verbosity=2).run(suite)
+tests_require = []
+if sys.version_info < (2, 7):
+ tests_require.append("unittest2")
def read(fname):
@@ -48,12 +17,12 @@ def read(fname):
return out
-setup(name='appdirs',
+setup(
+ name='appdirs',
version=appdirs.__version__,
description='A small Python module for determining appropriate " + \
"platform-specific dirs, e.g. a "user data dir".',
long_description=read('README.rst') + '\n' + read('CHANGES.rst'),
- cmdclass={'test': RunTests},
classifiers=[c.strip() for c in """
Development Status :: 4 - Beta
Intended Audience :: Developers
@@ -69,7 +38,8 @@ setup(name='appdirs',
Programming Language :: Python :: 3.2
Topic :: Software Development :: Libraries :: Python Modules
""".split('\n') if c.strip()],
- requires=requires_list,
+ test_suite='test.test_api',
+ tests_require=tests_require,
keywords='application directory log cache user',
author='Trent Mick',
author_email='trentm@gmail.com',
diff --git a/test/test_api.py b/test/test_api.py
index bcf36cb..6cc584a 100644
--- a/test/test_api.py
+++ b/test/test_api.py
@@ -1,27 +1,38 @@
-import unittest
+import sys
import appdirs
+if sys.version_info < (2, 7):
+ import unittest2 as unittest
+else:
+ import unittest
+
+if sys.version_info[0] < 3:
+ STRING_TYPE = basestring
+else:
+ STRING_TYPE = str
+
+
class Test_AppDir(unittest.TestCase):
def test_metadata(self):
self.assertTrue(hasattr(appdirs, "__version__"))
self.assertTrue(hasattr(appdirs, "__version_info__"))
def test_helpers(self):
- self.assertTrue(isinstance(
- appdirs.user_data_dir('MyApp', 'MyCompany'), str))
- self.assertTrue(isinstance(
- appdirs.site_data_dir('MyApp', 'MyCompany'), str))
- self.assertTrue(isinstance(
- appdirs.user_cache_dir('MyApp', 'MyCompany'), str))
- self.assertTrue(isinstance(
- appdirs.user_log_dir('MyApp', 'MyCompany'), str))
+ self.assertIsInstance(
+ appdirs.user_data_dir('MyApp', 'MyCompany'), STRING_TYPE)
+ self.assertIsInstance(
+ appdirs.site_data_dir('MyApp', 'MyCompany'), STRING_TYPE)
+ self.assertIsInstance(
+ appdirs.user_cache_dir('MyApp', 'MyCompany'), STRING_TYPE)
+ self.assertIsInstance(
+ appdirs.user_log_dir('MyApp', 'MyCompany'), STRING_TYPE)
def test_dirs(self):
dirs = appdirs.AppDirs('MyApp', 'MyCompany', version='1.0')
- self.assertTrue(isinstance(dirs.user_data_dir, str))
- self.assertTrue(isinstance(dirs.site_data_dir, str))
- self.assertTrue(isinstance(dirs.user_cache_dir, str))
- self.assertTrue(isinstance(dirs.user_log_dir, str))
+ self.assertIsInstance(dirs.user_data_dir, STRING_TYPE)
+ self.assertIsInstance(dirs.site_data_dir, STRING_TYPE)
+ self.assertIsInstance(dirs.user_cache_dir, STRING_TYPE)
+ self.assertIsInstance(dirs.user_log_dir, STRING_TYPE)
-if __name__=="__main__":
+if __name__ == "__main__":
unittest.main()