1import pytest 2 3# Renamed these imports so that them being in the namespace will not 4# cause pytest 3 to discover them as tests and then complain that 5# they have __init__ defined. 6from astropy.tests.runner import TestRunner as _TestRunner 7from astropy.tests.runner import TestRunnerBase as _TestRunnerBase 8from astropy.tests.runner import keyword 9 10 11def test_disable_kwarg(): 12 class no_remote_data(_TestRunner): 13 @keyword() 14 def remote_data(self, remote_data, kwargs): 15 return NotImplemented 16 17 r = no_remote_data('.') 18 with pytest.raises(TypeError): 19 r.run_tests(remote_data='bob') 20 21 22def test_wrong_kwarg(): 23 r = _TestRunner('.') 24 with pytest.raises(TypeError): 25 r.run_tests(spam='eggs') 26 27 28def test_invalid_kwarg(): 29 class bad_return(_TestRunnerBase): 30 @keyword() 31 def remote_data(self, remote_data, kwargs): 32 return 'bob' 33 34 r = bad_return('.') 35 with pytest.raises(TypeError): 36 r.run_tests(remote_data='bob') 37 38 39def test_new_kwarg(): 40 class Spam(_TestRunnerBase): 41 @keyword() 42 def spam(self, spam, kwargs): 43 return [spam] 44 45 r = Spam('.') 46 47 args = r._generate_args(spam='spam') 48 49 assert ['spam'] == args 50 51 52def test_priority(): 53 class Spam(_TestRunnerBase): 54 @keyword() 55 def spam(self, spam, kwargs): 56 return [spam] 57 58 @keyword(priority=1) 59 def eggs(self, eggs, kwargs): 60 return [eggs] 61 62 r = Spam('.') 63 64 args = r._generate_args(spam='spam', eggs='eggs') 65 66 assert ['eggs', 'spam'] == args 67 68 69def test_docs(): 70 class Spam(_TestRunnerBase): 71 @keyword() 72 def spam(self, spam, kwargs): 73 """ 74 Spam Spam Spam 75 """ 76 return [spam] 77 78 @keyword() 79 def eggs(self, eggs, kwargs): 80 """ 81 eggs asldjasljd 82 """ 83 return [eggs] 84 85 r = Spam('.') 86 assert "eggs" in r.run_tests.__doc__ 87 assert "Spam Spam Spam" in r.run_tests.__doc__ 88