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 /unit_tests | |
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 'unit_tests')
-rw-r--r-- | unit_tests/test_core.py | 48 |
1 files changed, 10 insertions, 38 deletions
diff --git a/unit_tests/test_core.py b/unit_tests/test_core.py index 6fb6cef..d84c085 100644 --- a/unit_tests/test_core.py +++ b/unit_tests/test_core.py @@ -33,64 +33,36 @@ class Undefined(object): pass class TestUsage(unittest.TestCase): - + def test_from_directory(self): usage_txt = nose.core.TestProgram.usage() assert usage_txt.startswith('nose collects tests automatically'), ( "Unexpected usage: '%s...'" % usage_txt[0:50].replace("\n", '\n')) - + def test_from_zip(self): requested_data = [] - + # simulates importing nose from a zip archive # with a zipimport.zipimporter instance class fake_zipimporter(object): - - prefix = '' - zipfile = '<fake zipfile>' - + def get_data(self, path): requested_data.append(path) - return "<usage>" - + # Return as str in Python 2, bytes in Python 3. + return '<usage>'.encode('utf-8') + existing_loader = getattr(nose, '__loader__', Undefined) try: nose.__loader__ = fake_zipimporter() usage_txt = nose.core.TestProgram.usage() self.assertEqual(usage_txt, '<usage>') - self.assertEqual(requested_data, ['nose%susage.txt' % os.sep]) + self.assertEqual(requested_data, [os.path.join( + os.path.dirname(nose.__file__), 'usage.txt')]) finally: if existing_loader is not Undefined: nose.__loader__ = existing_loader else: del nose.__loader__ - - def test_from_zip_with_prefix(self): - requested_data = [] - - # simulates importing nose from a zip archive - # with a zipimport.zipimporter instance - class fake_zipimporter(object): - - prefix = 'PREFIX' - zipfile = '<fake zipfile>' - - def get_data(self, path): - requested_data.append(path) - return "<usage>" - - existing_loader = getattr(nose, '__loader__', Undefined) - try: - nose.__loader__ = fake_zipimporter() - usage_txt = nose.core.TestProgram.usage() - self.assertEqual(usage_txt, '<usage>') - self.assertEqual(requested_data, - ['PREFIX%snose%susage.txt' % (os.sep, os.sep)]) - finally: - if existing_loader is not Undefined: - nose.__loader__ = existing_loader - else: - del nose.__loader__ - + if __name__ == '__main__': unittest.main() |