Example #1
0
def test_system_category_windows(
    instantiate: Callable[[lt.error_code], ltpy.Error],
    value: int,
    result_cls: type[ltpy.OSError],
) -> None:
    ec = lt.error_code(value, lt.system_category())
    assert isinstance(instantiate(ec), result_cls)
Example #2
0
 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")
Example #3
0
    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')
Example #4
0
    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')
Example #5
0
    value: int,
    result_cls: type[ltpy.Error],
) -> None:
    ec = lt.error_code(value, lt.libtorrent_category())
    assert isinstance(instantiate(ec), result_cls)


@pytest.mark.parametrize(
    "instantiate", (ltpy.Error, ltpy.OSError, ltpy.exception_from_error_code)
)
# system_category should be the same as generic_category on non-windows
@pytest.mark.parametrize(
    "category",
    (
        lt.generic_category(),
        pytest.param(lt.system_category(), marks=pytest.mark.skipif('os.name == "nt"')),
    ),
)
# Mapping from pep3151
@pytest.mark.parametrize(
    ("value", "result_cls"),
    (
        (errno.EAGAIN, ltpy.BlockingIOError),
        (errno.EALREADY, ltpy.BlockingIOError),
        (errno.EWOULDBLOCK, ltpy.BlockingIOError),
        (errno.EINPROGRESS, ltpy.BlockingIOError),
        (errno.ECHILD, ltpy.ChildProcessError),
        (errno.EPIPE, ltpy.BrokenPipeError),
        (errno.ESHUTDOWN, ltpy.BrokenPipeError),
        (errno.ECONNABORTED, ltpy.ConnectionAbortedError),
        (errno.ECONNREFUSED, ltpy.ConnectionRefusedError),
Example #6
0
 def test_clear(self) -> None:
     ec = lt.error_code(errno.ENOENT, lt.generic_category())
     ec.clear()
     self.assertEqual(ec.value(), 0)
     self.assertEqual(ec.category(), lt.system_category())
Example #7
0
 def test_equal(self) -> None:
     self.assertEqual(lt.generic_category(), lt.generic_category())
     self.assertNotEqual(lt.generic_category(), lt.system_category())
Example #8
0
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):
Example #9
0
# PERFORMANCE OF THIS SOFTWARE.
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