예제 #1
0
 def test_valid_method_post_import(self):
     # Test that it returns a classmethod after the module has been imported
     from tarfile import TarInfo
     from_file_via_validator = _string_to_attribute('tarfile.TarInfo.frombuf', type_='function')
     assert from_file_via_validator == TarInfo.frombuf
예제 #2
0
 def test_invalid_functions(self, value, message):
     with pytest.raises(ValueError) as exc:
         _string_to_attribute(value, type_='function')
     assert re.search(message.format('a function'), exc.value.args[0])
예제 #3
0
 def test_valid_method_pre_import(self):
     # Test that it returns a classmethod
     from_file_via_validator = _string_to_attribute('tarfile.TarInfo.frombuf', type_='function')
     from tarfile import TarInfo
     assert from_file_via_validator == TarInfo.frombuf
예제 #4
0
 def test_valid_function_post_import(self):
     # A function from inside a module after the module has been imported
     from itertools import chain
     chain_via_validator = _string_to_attribute('itertools.chain', type_='function')
     assert chain_via_validator == chain
예제 #5
0
 def test_valid_function_pre_import(self):
     # A function inside a module
     chain_via_validator = _string_to_attribute('itertools.chain', type_='function')
     from itertools import chain
     assert chain_via_validator == chain
예제 #6
0
 def test_valid_attribute_post_import(self):
     from os import F_OK
     f_ok_via_validator = _string_to_attribute('os.F_OK')
     assert f_ok_via_validator == F_OK
예제 #7
0
    def test_valid_builtin(self):

        # A toplevel function
        assert _string_to_attribute('dir', type_='function') == dir