OLD | NEW |
1 # Copyright 2014 Dirk Pranke. All rights reserved. | 1 # Copyright 2014 Dirk Pranke. All rights reserved. |
2 # | 2 # |
3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
6 # | 6 # |
7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
8 # | 8 # |
9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 self.check(['-l', '../foo/pass_test.py'], files=files, cwd='bar', | 347 self.check(['-l', '../foo/pass_test.py'], files=files, cwd='bar', |
348 ret=0, err='', | 348 ret=0, err='', |
349 out='foo.pass_test.PassingTest.test_pass\n') | 349 out='foo.pass_test.PassingTest.test_pass\n') |
350 self.check(['-l', 'foo'], files=files, cwd='bar', | 350 self.check(['-l', 'foo'], files=files, cwd='bar', |
351 ret=0, err='', | 351 ret=0, err='', |
352 out='foo.pass_test.PassingTest.test_pass\n') | 352 out='foo.pass_test.PassingTest.test_pass\n') |
353 self.check(['-l', '--path', '../foo', 'pass_test'], | 353 self.check(['-l', '--path', '../foo', 'pass_test'], |
354 files=files, cwd='bar', ret=0, err='', | 354 files=files, cwd='bar', ret=0, err='', |
355 out='pass_test.PassingTest.test_pass\n') | 355 out='pass_test.PassingTest.test_pass\n') |
356 | 356 |
| 357 def test_multiple_top_level_dirs(self): |
| 358 files = { |
| 359 'foo/bar/__init__.py': '', |
| 360 'foo/bar/pass_test.py': PASS_TEST_PY, |
| 361 'baz/quux/__init__.py': '', |
| 362 'baz/quux/second_test.py': PASS_TEST_PY, |
| 363 } |
| 364 self.check(['-l', 'foo/bar', 'baz/quux'], files=files, |
| 365 ret=0, err='', |
| 366 out=( |
| 367 'bar.pass_test.PassingTest.test_pass\n' |
| 368 'quux.second_test.PassingTest.test_pass\n' |
| 369 )) |
| 370 self.check(['-l', 'foo/bar/pass_test.py', 'baz/quux'], files=files, |
| 371 ret=0, err='', |
| 372 out=( |
| 373 'bar.pass_test.PassingTest.test_pass\n' |
| 374 'quux.second_test.PassingTest.test_pass\n' |
| 375 )) |
| 376 self.check(['-l', '--top-level-dirs', 'foo', '--top-level-dirs', 'baz'], |
| 377 files=files, |
| 378 ret=0, err='', |
| 379 out=( |
| 380 'bar.pass_test.PassingTest.test_pass\n' |
| 381 'quux.second_test.PassingTest.test_pass\n' |
| 382 )) |
| 383 |
| 384 def test_single_top_level_dir(self): |
| 385 files = { |
| 386 'foo/bar/__init__.py': '', |
| 387 'foo/bar/pass_test.py': PASS_TEST_PY, |
| 388 'baz/quux/__init__.py': '', |
| 389 'baz/quux/second_test.py': PASS_TEST_PY, |
| 390 } |
| 391 self.check(['-l', '--top-level-dir', 'foo'], |
| 392 files=files, |
| 393 ret=0, err='', |
| 394 out=( |
| 395 'bar.pass_test.PassingTest.test_pass\n' |
| 396 )) |
| 397 |
| 398 def test_can_not_have_both_top_level_flags(self): |
| 399 files = { |
| 400 'foo/bar/__init__.py': '', |
| 401 'foo/bar/pass_test.py': PASS_TEST_PY, |
| 402 'baz/quux/__init__.py': '', |
| 403 'baz/quux/second_test.py': PASS_TEST_PY, |
| 404 } |
| 405 self.check( |
| 406 ['-l', '--top-level-dir', 'foo', '--top-level-dirs', 'bar'], |
| 407 files=files, |
| 408 ret=1, out='', |
| 409 err='Cannot specify both --top-level-dir and --top-level-dirs\n') |
| 410 |
357 def test_help(self): | 411 def test_help(self): |
358 self.check(['--help'], ret=0, rout='.*', err='') | 412 self.check(['--help'], ret=0, rout='.*', err='') |
359 | 413 |
360 def test_import_failure_missing_file(self): | 414 def test_import_failure_missing_file(self): |
361 _, out, _, _ = self.check(['-l', 'foo'], ret=1, err='') | 415 _, out, _, _ = self.check(['-l', 'foo'], ret=1, err='') |
362 self.assertIn('Failed to load "foo" in find_tests', out) | 416 self.assertIn('Failed to load "foo" in find_tests', out) |
363 self.assertIn('No module named foo', out) | 417 self.assertIn('No module named', out) |
364 | 418 |
365 def test_import_failure_missing_package(self): | 419 def test_import_failure_missing_package(self): |
366 files = {'foo.py': d("""\ | 420 files = {'foo.py': d("""\ |
367 import unittest | 421 import unittest |
368 import package_that_does_not_exist | 422 import package_that_does_not_exist |
369 | 423 |
370 class ImportFailureTest(unittest.TestCase): | 424 class ImportFailureTest(unittest.TestCase): |
371 def test_case(self): | 425 def test_case(self): |
372 pass | 426 pass |
373 """)} | 427 """)} |
374 _, out, _, _ = self.check(['-l', 'foo.py'], files=files, ret=1, err='') | 428 _, out, _, _ = self.check(['-l', 'foo.py'], files=files, ret=1, err='') |
375 self.assertIn('Failed to load "foo.py" in find_tests', out) | 429 self.assertIn('Failed to load "foo.py" in find_tests', out) |
376 self.assertIn('No module named package_that_does_not_exist', out) | 430 self.assertIn('No module named', out) |
377 | 431 |
378 def test_import_failure_no_tests(self): | 432 def test_import_failure_no_tests(self): |
379 files = {'foo.py': 'import unittest'} | 433 files = {'foo.py': 'import unittest'} |
380 self.check(['-l', 'foo'], files=files, ret=0, err='', | 434 self.check(['-l', 'foo'], files=files, ret=0, err='', |
381 out='\n') | 435 out='\n') |
382 | 436 |
383 def test_import_failure_syntax_error(self): | 437 def test_import_failure_syntax_error(self): |
384 files = {'syn_test.py': d("""\ | 438 files = {'syn_test.py': d("""\ |
385 import unittest | 439 import unittest |
386 | 440 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 modules_to_unload.append(k) | 820 modules_to_unload.append(k) |
767 for k in modules_to_unload: | 821 for k in modules_to_unload: |
768 del sys.modules[k] | 822 del sys.modules[k] |
769 sys.path = orig_sys_path | 823 sys.path = orig_sys_path |
770 | 824 |
771 return ret, out, err | 825 return ret, out, err |
772 | 826 |
773 def test_debugger(self): | 827 def test_debugger(self): |
774 # TODO: this test seems to hang under coverage. | 828 # TODO: this test seems to hang under coverage. |
775 pass | 829 pass |
OLD | NEW |