def test_exception(self): ex = OptionalPackageRequirementError('python-magic') self.assertTrue( str(ex).startswith('The following packages are missing')) self.assertRaises(ValueError, OptionalPackageRequirementError, 'PackageThatNotFoundInRequirements-optional.txt')
def ensure_aws4auth(): """ .. warning:: :exc:`.OptionalPackageRequirementError` will be raised if ``requests-aws4auth`` is not installed. """ if AWS4Auth is None: # pragma: no cover raise OptionalPackageRequirementError('requests-aws4auth')
def ensure_wand(): """ .. warning:: :exc:`.OptionalPackageRequirementError` will be raised if ``wand`` is not installed. """ if wand is None: # pragma: no cover raise OptionalPackageRequirementError('wand')
def ensure_os2auth(): """ .. warning:: :exc:`.OptionalPackageRequirementError` will be raised if ``requests-aliyun`` is not installed. """ if OS2Auth is None: # pragma: no cover raise OptionalPackageRequirementError('requests-aliyun')
def ensure_paramiko(): """ .. warning:: :exc:`.OptionalPackageRequirementError` will be raised if ``paramiko`` is not installed. """ if paramiko is None: # pragma: no cover raise OptionalPackageRequirementError('paramiko')
def magic_mime_from_buffer(buffer: bytes) -> str: """ Try to detect mimetype using ``magic`` library. .. warning:: :exc:`.OptionalPackageRequirementError` will be raised if ``python-magic`` is not installed. :param buffer: buffer from header of file. :return: The mimetype """ if magic is None: # pragma: no cover raise OptionalPackageRequirementError('python-magic') return magic.from_buffer(buffer, mime=True)