diff options
author | Bradley M. Froehle <brad.froehle@gmail.com> | 2012-10-26 12:58:15 -0700 |
---|---|---|
committer | Bradley M. Froehle <brad.froehle@gmail.com> | 2012-12-27 19:11:14 -0800 |
commit | 9d4056bc01981a2a9674a640e7c71fe36a6b69c6 (patch) | |
tree | 5f69edd5a77a14962fb7b32a062cdcf39dd58129 /nose/core.py | |
parent | e879960507d51a4510a0900c784676951fc9581b (diff) | |
download | nose-9d4056bc01981a2a9674a640e7c71fe36a6b69c6.tar.gz |
Use `nose.__loader__` to load 'usage.txt', if available.
Previously we only used `nose.__loader__` if we thought
that the loader was zipimporter. Additionally, we use
`nose.__file__` to build the path to 'usage.txt' as
suggested by PEP-302.
Diffstat (limited to 'nose/core.py')
-rw-r--r-- | nose/core.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/nose/core.py b/nose/core.py index b78f232..e57a88f 100644 --- a/nose/core.py +++ b/nose/core.py @@ -237,14 +237,21 @@ class TestProgram(unittest.TestProgram): def usage(cls): import nose - if hasattr(nose, '__loader__'): + try: ld = nose.__loader__ - if hasattr(ld, 'zipfile'): - # nose was imported from a zipfile - return ld.get_data( - os.path.join(ld.prefix, 'nose', 'usage.txt')) - return open(os.path.join( - os.path.dirname(__file__), 'usage.txt'), 'r').read() + text = ld.get_data(os.path.join( + os.path.dirname(__file__), 'usage.txt')) + except AttributeError: + f = open(os.path.join( + os.path.dirname(__file__), 'usage.txt'), 'r') + try: + text = f.read() + finally: + f.close() + # Ensure that we return str, not bytes. + if not isinstance(text, str): + text = text.decode('utf-8') + return text usage = classmethod(usage) # backwards compatibility |