def test_error_code(self): a = lt.error_code() a = lt.error_code(10, lt.libtorrent_category()) self.assertEqual(a.category().name(), 'libtorrent') self.assertEqual(lt.libtorrent_category().name(), 'libtorrent') self.assertEqual(lt.upnp_category().name(), 'upnp') self.assertEqual(lt.http_category().name(), 'http') self.assertEqual(lt.socks_category().name(), 'socks') self.assertEqual(lt.bdecode_category().name(), 'bdecode') self.assertEqual(lt.generic_category().name(), 'generic') self.assertEqual(lt.system_category().name(), 'system')
def test_subtypes_libtorrenterror( instantiate: Callable[[lt.error_code], ltpy.Error], value: int, result_cls: type[ltpy.Error], ) -> None: ec = lt.error_code(value, lt.libtorrent_category()) assert isinstance(instantiate(ec), result_cls)
def test_duplicate_torrent() -> None: with pytest.raises(ltpy.DuplicateTorrentError): with ltpy.translate_exceptions(): raise RuntimeError( lt.libtorrent_category().message( ltpy.LibtorrentErrorValue.DUPLICATE_TORRENT ) )
def test_name(self) -> None: self.assertEqual(lt.generic_category().name(), "generic") self.assertEqual(lt.system_category().name(), "system") self.assertEqual(lt.libtorrent_category().name(), "libtorrent") self.assertEqual(lt.upnp_category().name(), "upnp") self.assertEqual(lt.http_category().name(), "http") self.assertEqual(lt.socks_category().name(), "socks") self.assertEqual(lt.bdecode_category().name(), "bdecode") self.assertEqual(lt.i2p_category().name(), "i2p error")
def test_accessors(self) -> None: with self.assertWarns(DeprecationWarning): self.assertEqual(lt.get_libtorrent_category(), lt.libtorrent_category()) with self.assertWarns(DeprecationWarning): self.assertEqual(lt.get_upnp_category(), lt.upnp_category()) with self.assertWarns(DeprecationWarning): self.assertEqual(lt.get_http_category(), lt.http_category()) with self.assertWarns(DeprecationWarning): self.assertEqual(lt.get_socks_category(), lt.socks_category()) with self.assertWarns(DeprecationWarning): self.assertEqual(lt.get_bdecode_category(), lt.bdecode_category()) with self.assertWarns(DeprecationWarning): self.assertEqual(lt.get_i2p_category(), lt.i2p_category())
def test_subtypes_oserror( instantiate: Callable[[lt.error_code], ltpy.Error], value: int, category: lt.error_category, result_cls: type[ltpy.OSError], ) -> None: ec = lt.error_code(value, category) assert isinstance(instantiate(ec), result_cls) @pytest.mark.parametrize("instantiate", (ltpy.Error, ltpy.exception_from_error_code)) @pytest.mark.parametrize( ("category", "cls"), ( (lt.generic_category(), ltpy.OSError), (lt.libtorrent_category(), ltpy.LibtorrentError), (lt.upnp_category(), ltpy.UPNPError), (lt.http_category(), ltpy.HTTPError), (lt.socks_category(), ltpy.SOCKSError), (lt.bdecode_category(), ltpy.BDecodeError), (lt.i2p_category(), ltpy.I2PError), ), ) def test_subtypes_top_level( instantiate: Callable[[lt.error_code], ltpy.Error], category: lt.error_category, cls: type[ltpy.Error], ) -> None: # use a nonce value ec = lt.error_code(123, category) assert isinstance(instantiate(ec), cls)
def test_assign(self) -> None: ec = lt.error_code(errno.ENOENT, lt.generic_category()) ec.assign(123, lt.libtorrent_category()) self.assertEqual(ec.value(), 123) self.assertEqual(ec.category(), lt.libtorrent_category())
import errno import os import pickle import unittest import libtorrent as lt ALL_CATEGORIES = ( lt.generic_category(), lt.system_category(), lt.libtorrent_category(), lt.upnp_category(), lt.http_category(), lt.socks_category(), lt.bdecode_category(), lt.i2p_category(), ) class ErrorCategoryTest(unittest.TestCase): def test_equal(self) -> None: self.assertEqual(lt.generic_category(), lt.generic_category()) self.assertNotEqual(lt.generic_category(), lt.system_category()) def test_accessors(self) -> None: with self.assertWarns(DeprecationWarning): self.assertEqual(lt.get_libtorrent_category(), lt.libtorrent_category()) with self.assertWarns(DeprecationWarning): self.assertEqual(lt.get_upnp_category(), lt.upnp_category()) with self.assertWarns(DeprecationWarning):
def create(cls: type[_C]) -> _C: ec = lt.error_code( LibtorrentErrorValue.INVALID_TORRENT_HANDLE, lt.libtorrent_category(), ) return cls(ec)
from __future__ import annotations import builtins import contextlib import enum import errno import os from typing import Generator from typing import Optional from typing import TypeVar import libtorrent as lt GENERIC_CATEGORY = lt.generic_category() SYSTEM_CATEGORY = lt.system_category() LIBTORRENT_CATEGORY = lt.libtorrent_category() UPNP_CATEGORY = lt.upnp_category() HTTP_CATEGORY = lt.http_category() SOCKS_CATEGORY = lt.socks_category() I2P_CATEGORY = lt.i2p_category() BDECODE_CATEGORY = lt.bdecode_category() class LibtorrentErrorValue(enum.IntEnum): DUPLICATE_TORRENT = 19 INVALID_TORRENT_HANDLE = 20 INVALID_SESSION_HANDLE = 115 class Error(RuntimeError):