repo_id stringclasses 409
values | prefix large_stringlengths 34 36.3k | target large_stringlengths 1 498 | assertion_type stringclasses 31
values | difficulty stringclasses 8
values | test_file stringlengths 10 121 | test_function stringlengths 1 104 | test_class stringlengths 0 51 | lineno int32 2 11.3k | commit_idx int32 |
|---|---|---|---|---|---|---|---|---|---|
python-attrs/attrs | import pytest
from attr._cmp import cmp_using
from attr._compat import PY_3_13_PLUS
EqCSameType = cmp_using(eq=lambda a, b: a == b, class_name="EqCSameType")
PartialOrderCSameType = cmp_using(
eq=lambda a, b: a == b,
lt=lambda a, b: a < b,
class_name="PartialOrderCSameType",
)
FullOrderCSameType = cmp_usi... | cls(1) | assert | func_call | tests/test_cmp.py | test_equal_same_type | TestEqOrder | 76 | null |
python-attrs/attrs | import copy
import inspect
import pickle
import pytest
from hypothesis import given
from hypothesis.strategies import booleans
import attr
from attr._make import (
NOTHING,
Factory,
_add_repr,
_compile_and_eval,
_make_init_script,
fields,
make_class,
)
from attr.validators import instanc... | obj.a | assert | complex_expr | tests/test_dunders.py | test_sets_attributes | TestAddInit | 806 | null |
python-attrs/attrs | import attr
def test_init_subclass_vanilla(slots):
"""
`super().__init_subclass__` can be used if the subclass is not an attrs
class both with dict and slotted classes.
"""
@attr.s(slots=slots)
class Base:
def __init_subclass__(cls, param, **kw):
super().__init_subclass__(*... | Vanilla().param | assert | func_call | tests/test_init_subclass.py | test_init_subclass_vanilla | 25 | null | |
python-attrs/attrs | import pickle
import pytest
import attr
from attr import Converter, Factory, attrib
from attr._compat import _AnnotationExtractor
from attr.converters import default_if_none, optional, pipe, to_bool
class TestDefaultIfNone:
@pytest.mark.parametrize("val", [1, 0, True, False, "foo", "", object()])
def test_... | c(val) | assert | func_call | tests/test_converters.py | test_not_none | TestDefaultIfNone | 203 | null |
python-attrs/attrs | import re
from collections import OrderedDict
from typing import Generic, NamedTuple, TypeVar
import pytest
from hypothesis import assume, given
from hypothesis import strategies as st
import attr
from attr import asdict, assoc, astuple, evolve, fields, has
from attr._compat import Mapping, Sequence
from attr.exce... | result | assert | variable | tests/test_funcs.py | test_non_atomic_types | TestAsTuple | 515 | null |
python-attrs/attrs | import functools
import pickle
import weakref
from unittest import mock
import pytest
import attr
import attrs
from attr._compat import PY_3_14_PLUS, PYPY
def tests_weakref_does_not_add_when_inheriting_with_weakref():
"""
`weakref_slot=True` does not add a new __weakref__ slot when inheriting
one.
... | 0 | assert | numeric_literal | tests/test_slots.py | test_slots_cached_property_is_not_called_at_construction | 1,078 | null | |
python-attrs/attrs | import abc
import inspect
import pytest
import attrs
from attr._compat import PY_3_10_PLUS, PY_3_12_PLUS
class TestUpdateAbstractMethods:
def test_remain_abstract(self, slots):
"""
If an attrs class inherits from an abstract class but doesn't implement
abstract methods, it remains abstr... | TypeError, match=expected_exception_message) | pytest.raises | complex_expr | tests/test_abc.py | test_remain_abstract | TestUpdateAbstractMethods | 61 | null |
python-attrs/attrs | import copy
import functools
import gc
import inspect
import itertools
import sys
import unicodedata
from operator import attrgetter
from typing import Generic, TypeVar
import pytest
from hypothesis import assume, given
from hypothesis.strategies import booleans, integers, lists, sampled_from, text
import attr
impo... | 3 | assert | numeric_literal | tests/test_make.py | test_kw_only | TestTransformAttrs | 270 | null |
python-attrs/attrs | import re
from collections import OrderedDict
from typing import Generic, NamedTuple, TypeVar
import pytest
from hypothesis import assume, given
from hypothesis import strategies as st
import attr
from attr import asdict, assoc, astuple, evolve, fields, has
from attr._compat import Mapping, Sequence
from attr.exce... | res | assert | variable | tests/test_funcs.py | test_dicts | TestAsDict | 191 | null |
python-attrs/attrs | import pytest
import attr
class TestPatternMatching:
def test_match_args_kw_only(self):
"""
kw_only classes don't generate __match_args__.
kw_only fields are not included in __match_args__.
"""
@attr.define
class C:
a = attr.field(kw_only=True)
... | (a, b) | assert | collection | tests/test_pattern_matching.py | test_match_args_kw_only | TestPatternMatching | 100 | null |
python-attrs/attrs | from __future__ import annotations
from datetime import datetime
import pytest
import attr
class TestTransformHook:
def test_hook_remove_field(self):
"""
It is possible to remove fields via the hook.
"""
def hook(cls, attribs):
attr.resolve_types(cls, attribs=attrib... | attr.asdict(C(2.7)) | assert | func_call | tests/test_hooks.py | test_hook_remove_field | TestTransformHook | 88 | null |
python-attrs/attrs | import re
from contextlib import contextmanager
from functools import partial
import pytest
import attr as _attr # don't use it by accident
import attrs
from attr._compat import PY_3_11_PLUS
from attr._make import ClassProps
class TestNextGen:
def test_exception(self):
"""
Exceptions are dete... | e.msg | assert | complex_expr | tests/test_next_gen.py | test_exception | TestNextGen | 205 | null |
python-attrs/attrs | import pickle
import pytest
import attr
from attr import setters
from attr.exceptions import FrozenAttributeError
from attr.validators import instance_of, matches_re
class TestSetAttr:
@pytest.mark.parametrize("a_slots", [True, False])
@pytest.mark.parametrize("b_slots", [True, False])
@pytest.mark.par... | False | assert | bool_literal | tests/test_setattr.py | test_setattr_inherited_do_not_reset_intermediate | TestSetAttr | 424 | null |
python-attrs/attrs | import copy
import inspect
import pickle
from copy import deepcopy
import pytest
from hypothesis import given
from hypothesis.strategies import booleans
import attr
from attr._compat import PY_3_13_PLUS
from attr._make import NOTHING, Attribute
from attr.exceptions import FrozenInstanceError
class TestFunctional:... | e1 | assert | variable | tests/test_functional.py | test_auto_exc | TestFunctional | 589 | null |
python-attrs/attrs | from .utils import simple_class
class TestSimpleClass:
def test_returns_class(self):
"""
Returns a class object.
"""
assert type is | simple_class().__class__ | assert | func_call | tests/test_utils.py | test_returns_class | TestSimpleClass | 13 | null |
python-attrs/attrs | import types
from typing import Protocol
import pytest
import attr
def _mp():
return types.MappingProxyType({"x": 42, "y": "foo"})
class TestMetadataProxy:
def test_immutable(self, mp):
"""
All mutating methods raise errors.
"""
with pytest.raises(TypeError, match="not supp... | AttributeError, match="no attribute 'update'") | pytest.raises | complex_expr | tests/test_compat.py | test_immutable | TestMetadataProxy | 43 | null |
python-attrs/attrs | from __future__ import annotations
from datetime import datetime
import pytest
import attr
class TestAsDictHook:
def test_asdict_calls(self):
"""
The correct instances and attribute names are passed to the hook.
"""
calls = []
def hook(inst, a, v):
calls.app... | calls | assert | variable | tests/test_hooks.py | test_asdict_calls | TestAsDictHook | 299 | null |
python-attrs/attrs | import copy
import inspect
import pickle
import pytest
from hypothesis import given
from hypothesis.strategies import booleans
import attr
from attr._make import (
NOTHING,
Factory,
_add_repr,
_compile_and_eval,
_make_init_script,
fields,
make_class,
)
from attr.validators import instanc... | i.a | assert | complex_expr | tests/test_dunders.py | test_default | TestAddInit | 823 | null |
python-attrs/attrs | from __future__ import annotations
from datetime import datetime
import pytest
import attr
class TestTransformHook:
def test_hook_applied(self):
"""
The transform hook is applied to all attributes. Types can be missing,
explicitly set, or annotated.
"""
results = []
... | results | assert | variable | tests/test_hooks.py | test_hook_applied | TestTransformHook | 35 | null |
python-attrs/attrs | import pytest
from attr import VersionInfo
def _vi():
return VersionInfo(19, 2, 0, "final")
class TestVersionInfo:
def test_order(self, vi):
"""
Ordering works as expected.
"""
assert vi < (20,)
assert vi < (19, 2, 1)
assert vi > | (0,) | assert | collection | tests/test_version_info.py | test_order | TestVersionInfo | 53 | null |
python-attrs/attrs | import functools
import pickle
import weakref
from unittest import mock
import pytest
import attr
import attrs
from attr._compat import PY_3_14_PLUS, PYPY
def test_basic_attr_funcs():
"""
Comparison, `__eq__`, `__hash__`, `__repr__`, `attrs.asdict` work.
"""
a = C1Slots(x=1, y=2)
b = C1Slots(x=... | a | assert | variable | tests/test_slots.py | test_basic_attr_funcs | 130 | null | |
python-attrs/attrs | from __future__ import annotations
from datetime import datetime
import pytest
import attr
class TestTransformHook:
def test_hook_conflicting_defaults_after_reorder(self):
"""
Raises `ValueError` if attributes with defaults are followed by
mandatory attributes after the hook reorders fi... | e.value.args | assert | complex_expr | tests/test_hooks.py | test_hook_conflicting_defaults_after_reorder | TestTransformHook | 174 | null |
python-attrs/attrs | import pytest
from attr import VersionInfo
def _vi():
return VersionInfo(19, 2, 0, "final")
class TestVersionInfo:
def test_from_string_no_releaselevel(self, vi):
"""
If there is no suffix, the releaselevel becomes "final" by default.
"""
assert vi == | VersionInfo._from_version_string("19.2.0") | assert | func_call | tests/test_version_info.py | test_from_string_no_releaselevel | TestVersionInfo | 19 | null |
python-attrs/attrs | import re
from contextlib import contextmanager
from functools import partial
import pytest
import attr as _attr # don't use it by accident
import attrs
from attr._compat import PY_3_11_PLUS
from attr._make import ClassProps
class TestNextGen:
def test_auto_attribs_detect_fields_and_annotations(self):
... | ["x", "y"] | assert | collection | tests/test_next_gen.py | test_auto_attribs_detect_fields_and_annotations | TestNextGen | 150 | null |
python-attrs/attrs | import pytest
from attr import _config
class TestConfig:
def test_wrong_type(self):
"""
Passing anything else than a boolean raises TypeError.
"""
with pytest.raises(TypeError) as e:
_config.set_run_validators("False")
assert "'run' must be bool." == | e.value.args[0] | assert | complex_expr | tests/test_config.py | test_wrong_type | TestConfig | 43 | null |
python-attrs/attrs | import re
from contextlib import contextmanager
from functools import partial
import pytest
import attr as _attr # don't use it by accident
import attrs
from attr._compat import PY_3_11_PLUS
from attr._make import ClassProps
class TestNextGen:
def test_exception(self):
"""
Exceptions are dete... | e.args | assert | complex_expr | tests/test_next_gen.py | test_exception | TestNextGen | 204 | null |
python-attrs/attrs | import pickle
import pytest
import attr
from attr import setters
from attr.exceptions import FrozenAttributeError
from attr.validators import instance_of, matches_re
class TestSetAttr:
@pytest.mark.parametrize(
"on_setattr",
[setters.validate, [setters.validate], setters.pipe(setters.validate)]... | va.y | assert | complex_expr | tests/test_setattr.py | test_validator | TestSetAttr | 91 | null |
python-attrs/attrs | import sys
import types
import typing
import pytest
import attr
import attrs
from attr._make import _is_class_var
from attr.exceptions import UnannotatedAttributeError
def assert_init_annotations(cls, **annotations):
"""
Assert cls.__init__ has the correct annotations.
"""
__tracebackhide__ = True
... | A) | assert_* | variable | tests/test_annotations.py | test_auto_attribs_subclassing | TestAnnotations | 199 | null |
python-escpos/python-escpos | import pytest
from PIL import Image
import escpos.printer as printer
from escpos.exceptions import ImageWidthError
def test_bit_image_colfmt_black() -> None:
"""
Test printing solid black bit image (column format)
"""
instance = printer.Dummy()
instance.image("test/resources/canvas_black.png", imp... | b"\x1b3\x10\x1b*!\x01\x00\x80\x00\x00\x0a\x1b2" | assert | string_literal | test/test_functions/test_function_image.py | test_bit_image_colfmt_black | 67 | null | |
python-escpos/python-escpos | import logging
import pytest
def test_open_raise_exception(fileprinter, devicenotfounderror):
"""
GIVEN a file printer object
WHEN open() is set to raise a DeviceNotFoundError on error
THEN check the exception is raised
"""
fileprinter.devfile = "fake/device"
with pytest.raises( | devicenotfounderror) | pytest.raises | variable | test/test_printers/test_printer_file.py | test_open_raise_exception | 33 | null | |
python-escpos/python-escpos | import pytest
from PIL import Image
import escpos.printer as printer
from escpos.exceptions import ImageWidthError
def test_bit_image_colfmt_white() -> None:
"""
Test printing solid white bit image (column format)
"""
instance = printer.Dummy()
instance.image("test/resources/canvas_white.png", imp... | b"\x1b3\x10\x1b*!\x01\x00\x00\x00\x00\x0a\x1b2" | assert | string_literal | test/test_functions/test_function_image.py | test_bit_image_colfmt_white | 76 | null | |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform == "win32", reason="skipping non Windows platform specific tests"
)
def test_open_not_raise_exception(lpprinter, caplog, mocker):
"""
GIVEN a lp printer object
WHEN open() is set to not raise on error but simply can... | None | assert | none_literal | test/test_printers/test_printer_lp.py | test_open_not_raise_exception | 59 | null | |
python-escpos/python-escpos | from typing import List
from escpos.image import EscposImage
def _load_and_check_img(
filename: str,
width_expected: int,
height_expected: int,
raster_format_expected: bytes,
column_format_expected: List[bytes],
) -> None:
"""
Load an image, and test whether raster & column formatted outpu... | raster_format_expected | assert | variable | test/test_image.py | _load_and_check_img | 78 | null | |
python-escpos/python-escpos | import pytest
from PIL import Image
import escpos.printer as printer
from escpos.exceptions import ImageWidthError
def test_bit_image_both() -> None:
"""
Test printing black/white bit image (raster)
"""
instance = printer.Dummy()
instance.image("test/resources/black_white.png", impl="bitImageRaste... | b"\x1dv0\x00\x01\x00\x02\x00\xc0\x00" | assert | string_literal | test/test_functions/test_function_image.py | test_bit_image_both | 48 | null | |
python-escpos/python-escpos | import pytest
import escpos.printer as printer
from escpos.capabilities import BARCODE_B, Profile
from escpos.exceptions import BarcodeCodeError, BarcodeTypeError
@pytest.mark.parametrize(
"bctype,supports_b",
[
("invalid", True),
("CODE128", False),
],
)
def test_lacks_support(bctype, sup... | b"" | assert | string_literal | test/test_functions/test_function_barcode.py | test_lacks_support | 41 | null | |
python-escpos/python-escpos | import pytest
@pytest.mark.parametrize("text_list", ["", [], None])
@pytest.mark.parametrize("widths", [30.5, "30", None])
@pytest.mark.parametrize("align", ["invalid_align_name", "", None])
def test_software_columns_invalid_args(driver, text_list, widths, align) -> None:
"""
GIVEN a dummy printer object
W... | (TypeError, ValueError)) | pytest.raises | collection | test/test_functions/test_function_software_columns.py | test_software_columns_invalid_args | 58 | null | |
python-escpos/python-escpos | import logging
import pytest
def test_open_not_raise_exception(networkprinter, caplog):
"""
GIVEN a network printer object
WHEN open() is set to not raise on error but simply cancel
THEN check the error is logged and open() canceled
"""
networkprinter.host = "fakehost"
with caplog.at_leve... | caplog.text | assert | complex_expr | test/test_printers/test_printer_network.py | test_open_not_raise_exception | 48 | null | |
python-escpos/python-escpos | import pytest
import escpos.printer as printer
from escpos.constants import QR_ECLEVEL_H, QR_MODEL_1
def test_empty() -> None:
"""Test QR printing blank code"""
instance = printer.Dummy()
instance.qr("", native=True)
assert instance.output == | b"" | assert | string_literal | test/test_functions/test_function_qr_native.py | test_empty | 32 | null | |
python-escpos/python-escpos | import pathlib
import platformdirs
import pytest
import escpos.exceptions
def generate_dummy_config(path, content=None):
"""Generate a dummy config in path"""
dummy_config_content = content
if not content:
dummy_config_content = "printer:\n type: Dummy\n"
path.write_text(dummy_config_conten... | b"1234" | assert | string_literal | test/test_config.py | simple_printer_test | 31 | null | |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform == "win32", reason="skipping non Windows platform specific tests"
)
def test_open(lpprinter, caplog, mocker):
"""
GIVEN a lp printer object and a mocked connection
WHEN a valid connection to a device is opened
T... | lpprinter.printers | assert | complex_expr | test/test_printers/test_printer_lp.py | test_open | 72 | null | |
python-escpos/python-escpos | from typing import Optional
import pytest
import escpos.printer as printer
from escpos.constants import SET_FONT, TXT_NORMAL, TXT_SIZE, TXT_STYLE
from escpos.exceptions import SetVariableError
def test_default_values_with_default() -> None:
"""Default test, please copy and paste this block to test set method cal... | b"".join(expected_sequence) | assert | string_literal | test/test_functions/test_function_set.py | test_default_values_with_default | 27 | null | |
python-escpos/python-escpos | import hypothesis.strategies as st
import mock
from hypothesis import given
from escpos.printer import Dummy
def get_printer() -> Dummy:
return Dummy(magic_encode_args={"disabled": True, "encoding": "CP437"})
def test_multiple_ln() -> None:
printer = get_printer()
printer.ln(3)
assert printer.output... | b"\n\n\n" | assert | string_literal | test/test_functions/test_function_text.py | test_multiple_ln | 62 | null | |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform != "win32", reason="Skipping Windows platform specific tests"
)
def test_open_raise_exception(win32rawprinter, devicenotfounderror):
"""
GIVEN a win32raw printer object
WHEN open() is set to raise a DeviceNotFoundEr... | devicenotfounderror) | pytest.raises | variable | test/test_printers/test_printer_win32raw.py | test_open_raise_exception | 39 | null | |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform == "win32", reason="skipping non Windows platform specific tests"
)
def test_raw_raise_exception(cupsprinter) -> None:
"""
GIVEN a cups printer object
WHEN passing a non byte string to _raw()
THEN check an excep... | TypeError) | pytest.raises | variable | test/test_printers/test_printer_cups.py | test_raw_raise_exception | 142 | null | |
python-escpos/python-escpos | import os
import shutil
import tempfile
from scripttest import TestFileEnvironment as TFE
import escpos
TEST_DIR = tempfile.mkdtemp() + "/cli-test"
DEVFILE_NAME = "testfile"
DEVFILE = os.path.join(TEST_DIR, DEVFILE_NAME)
CONFIGFILE = "testconfig.yaml"
CONFIG_YAML = f"""
---
printer:
type: file
devfile: {D... | 2 | assert | numeric_literal | test/test_cli.py | test_cli_text_invalid_args | TestCLI | 114 | null |
python-escpos/python-escpos | import pytest
from escpos import printer
from escpos.constants import BUZZER
@pytest.mark.parametrize(
"times, duration, expected_message",
[
[0, 0, "times must be between 1 and 9"],
[-1, 0, "times must be between 1 and 9"],
[10, 0, "times must be between 1 and 9"],
[11, 0, "ti... | ValueError) | pytest.raises | variable | test/test_functions/test_function_buzzer.py | test_buzzer_fuction_with_outrange_values | 52 | null | |
python-escpos/python-escpos | import types
import typing
import hypothesis.strategies as st
import pytest
from hypothesis import example, given
from escpos import printer
from escpos.exceptions import Error
from escpos.katakana import encode_katakana
from escpos.magicencode import Encoder, MagicEncode
class TestEncoder:
def test_find_suitab... | "CP857" | assert | string_literal | test/test_magicencode.py | test_find_suitable_encoding_unnecessary_codepage_swap | TestEncoder | 42 | null |
python-escpos/python-escpos | import types
import typing
import hypothesis.strategies as st
import pytest
from hypothesis import example, given
from escpos import printer
from escpos.exceptions import Error
from escpos.katakana import encode_katakana
from escpos.magicencode import Encoder, MagicEncode
class TestKatakana:
def test_result(sel... | b"\xb6\xc0\xb6\xc5" | assert | string_literal | test/test_magicencode.py | test_result | TestKatakana | 132 | null |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform == "win32", reason="skipping non Windows platform specific tests"
)
def test_read_no_device(cupsprinter) -> None:
"""
GIVEN a cups printer object
WHEN device is None
THEN check the return value is b'8'
"""
... | b"8" | assert | string_literal | test/test_printers/test_printer_cups.py | test_read_no_device | 176 | null | |
python-escpos/python-escpos | import pytest
from escpos.printer import Dummy
def test_line_spacing_rest() -> None:
printer = Dummy()
printer.line_spacing()
assert printer.output == | b"\x1b2" | assert | string_literal | test/test_functions/test_functions.py | test_line_spacing_rest | 15 | null | |
python-escpos/python-escpos | import pytest
import escpos.printer as printer
from escpos.capabilities import BARCODE_B, Profile
from escpos.exceptions import BarcodeCodeError, BarcodeTypeError
@pytest.mark.parametrize(
"bctype,data",
[
("EAN13", "AA"),
("CODE128", "{D2354AA"),
],
)
def test_code_check(bctype, data):
... | BarcodeCodeError) | pytest.raises | variable | test/test_functions/test_function_barcode.py | test_code_check | 54 | null | |
python-escpos/python-escpos | import hypothesis.strategies as st
import mock
from hypothesis import given
from escpos.printer import Dummy
def get_printer() -> Dummy:
return Dummy(magic_encode_args={"disabled": True, "encoding": "CP437"})
@given(text=st.text())
def test_text(text: str):
"""Test that text() calls the MagicEncode object.""... | text) | assert_* | variable | test/test_functions/test_function_text.py | test_text | 28 | null | |
python-escpos/python-escpos | import logging
import pytest
def test_open_not_raise_exception(fileprinter, caplog):
"""
GIVEN a file printer object
WHEN open() is set to not raise on error but simply cancel
THEN check the error is logged and open() canceled
"""
fileprinter.devfile = "fake/device"
with caplog.at_level(l... | None | assert | none_literal | test/test_printers/test_printer_file.py | test_open_not_raise_exception | 49 | null | |
python-escpos/python-escpos | import pytest
from escpos import printer
from escpos.constants import BUZZER
@pytest.mark.parametrize(
"times, duration, expected_message",
[
[0, 0, "times must be between 1 and 9"],
[-1, 0, "times must be between 1 and 9"],
[10, 0, "times must be between 1 and 9"],
[11, 0, "ti... | expected_message | assert | variable | test/test_functions/test_function_buzzer.py | test_buzzer_fuction_with_outrange_values | 55 | null | |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform == "win32", reason="skipping non Windows platform specific tests"
)
def test_open_not_raise_exception(cupsprinter, caplog) -> None:
"""
GIVEN a cups printer object
WHEN open() is set to not raise on error but simply... | None | assert | none_literal | test/test_printers/test_printer_cups.py | test_open_not_raise_exception | 55 | null | |
python-escpos/python-escpos | import logging
import pytest
def test_open_not_raise_exception(serialprinter, caplog):
"""
GIVEN a serial printer object
WHEN open() is set to not raise on error but simply cancel
THEN check the error is logged and open() canceled
"""
serialprinter.devfile = "fake/device"
with caplog.at_l... | None | assert | none_literal | test/test_printers/test_printer_serial.py | test_open_not_raise_exception | 49 | null | |
python-escpos/python-escpos | import pytest
from PIL import Image
import escpos.printer as printer
from escpos.exceptions import ImageWidthError
def test_large_graphics() -> None:
"""
Test whether 'large' graphics that induce a fragmentation are handled correctly.
"""
instance = printer.Dummy()
instance.image(
"test/re... | b"\x1dv0\x00\x01\x00\x01\x00\xc0\x1dv0\x00\x01\x00\x01\x00\x00" | assert | string_literal | test/test_functions/test_function_image.py | test_large_graphics | 158 | null | |
python-escpos/python-escpos | import logging
import pytest
def test_open_raise_exception(serialprinter, devicenotfounderror):
"""
GIVEN a serial printer object
WHEN open() is set to raise a DeviceNotFoundError on error
THEN check the exception is raised
"""
serialprinter.devfile = "fake/device"
with pytest.raises( | devicenotfounderror) | pytest.raises | variable | test/test_printers/test_printer_serial.py | test_open_raise_exception | 33 | null | |
python-escpos/python-escpos | import pytest
from escpos.printer import Dummy
def test_line_spacing_code_gen() -> None:
printer = Dummy()
printer.line_spacing(10)
assert printer.output == | b"\x1b3\n" | assert | string_literal | test/test_functions/test_functions.py | test_line_spacing_code_gen | 9 | null | |
python-escpos/python-escpos | import pytest
from PIL import Image
import escpos.printer as printer
from escpos.exceptions import ImageWidthError
def test_bit_image_colfmt_both() -> None:
"""
Test printing black/white bit image (column format)
"""
instance = printer.Dummy()
instance.image("test/resources/black_white.png", impl=... | b"\x1b3\x10\x1b*!\x02\x00\x80\x00\x00\x80\x00\x00\x0a\x1b2" | assert | string_literal | test/test_functions/test_function_image.py | test_bit_image_colfmt_both | 85 | null | |
python-escpos/python-escpos | import logging
import pytest
def test_open_not_raise_exception(fileprinter, caplog):
"""
GIVEN a file printer object
WHEN open() is set to not raise on error but simply cancel
THEN check the error is logged and open() canceled
"""
fileprinter.devfile = "fake/device"
with caplog.at_level(l... | caplog.text | assert | complex_expr | test/test_printers/test_printer_file.py | test_open_not_raise_exception | 48 | null | |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform == "win32", reason="skipping non Windows platform specific tests"
)
def test_open_not_raise_exception(cupsprinter, caplog) -> None:
"""
GIVEN a cups printer object
WHEN open() is set to not raise on error but simply... | caplog.text | assert | complex_expr | test/test_printers/test_printer_cups.py | test_open_not_raise_exception | 54 | null | |
python-escpos/python-escpos | import types
import typing
import hypothesis.strategies as st
import pytest
from hypothesis import example, given
from escpos import printer
from escpos.exceptions import Error
from escpos.katakana import encode_katakana
from escpos.magicencode import Encoder, MagicEncode
class TestForceEncoding:
def tes... | b"\x1bt\x00" | assert | string_literal | test/test_magicencode.py | test | TestForceEncoding | 109 | null |
python-escpos/python-escpos | import logging
import pytest
def test_open_not_raise_exception(networkprinter, caplog):
"""
GIVEN a network printer object
WHEN open() is set to not raise on error but simply cancel
THEN check the error is logged and open() canceled
"""
networkprinter.host = "fakehost"
with caplog.at_leve... | None | assert | none_literal | test/test_printers/test_printer_network.py | test_open_not_raise_exception | 49 | null | |
python-escpos/python-escpos | import os
import shutil
import tempfile
from scripttest import TestFileEnvironment as TFE
import escpos
TEST_DIR = tempfile.mkdtemp() + "/cli-test"
DEVFILE_NAME = "testfile"
DEVFILE = os.path.join(TEST_DIR, DEVFILE_NAME)
CONFIGFILE = "testconfig.yaml"
CONFIG_YAML = f"""
---
printer:
type: file
devfile: {D... | "\x1bt\x00" + test_text + "\n" | assert | string_literal | test/test_cli.py | test_cli_text | TestCLI | 103 | null |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform != "win32", reason="Skipping Windows platform specific tests"
)
def test_device_not_initialized(win32rawprinter):
"""
GIVEN a win32raw printer object
WHEN it is not initialized
THEN check the device property is ... | False | assert | bool_literal | test/test_printers/test_printer_win32raw.py | test_device_not_initialized | 28 | null | |
python-escpos/python-escpos | import types
import typing
import hypothesis.strategies as st
import pytest
from hypothesis import example, given
from escpos import printer
from escpos.exceptions import Error
from escpos.katakana import encode_katakana
from escpos.magicencode import Encoder, MagicEncode
class TestEncoder:
def test_find_suitab... | "CP858" | assert | string_literal | test/test_magicencode.py | test_find_suitable_encoding | TestEncoder | 35 | null |
python-escpos/python-escpos | from typing import Optional
import pytest
import escpos.printer as printer
from escpos.constants import SET_FONT, TXT_NORMAL, TXT_SIZE, TXT_STYLE
from escpos.exceptions import SetVariableError
def test_default_values() -> None:
"""Default test"""
instance = printer.Dummy()
instance.set()
assert ins... | b"" | assert | string_literal | test/test_functions/test_function_set.py | test_default_values | 35 | null | |
python-escpos/python-escpos | import hypothesis.strategies as st
import mock
from hypothesis import given
from escpos.printer import Dummy
def get_printer() -> Dummy:
return Dummy(magic_encode_args={"disabled": True, "encoding": "CP437"})
def test_textln_empty() -> None:
printer = get_printer()
printer.textln()
assert printer.ou... | b"\n" | assert | string_literal | test/test_functions/test_function_text.py | test_textln_empty | 50 | null | |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform == "win32", reason="skipping non Windows platform specific tests"
)
def test_flush(lpprinter, mocker):
"""
GIVEN a lp printer object and a mocked connection
WHEN auto_flush is disabled and flush() issued manually
... | 1 | assert | numeric_literal | test/test_printers/test_printer_lp.py | test_flush | 116 | null | |
python-escpos/python-escpos | import pathlib
import platformdirs
import pytest
import escpos.exceptions
def generate_dummy_config(path, content=None):
"""Generate a dummy config in path"""
dummy_config_content = content
if not content:
dummy_config_content = "printer:\n type: Dummy\n"
path.write_text(dummy_config_conten... | dummy_config_content | assert | variable | test/test_config.py | generate_dummy_config | 23 | null | |
python-escpos/python-escpos | import types
import typing
import hypothesis.strategies as st
import pytest
from hypothesis import example, given
from escpos import printer
from escpos.exceptions import Error
from escpos.katakana import encode_katakana
from escpos.magicencode import Encoder, MagicEncode
class TestWrite:
def test_write... | b"? ist teuro." | assert | string_literal | test/test_magicencode.py | test_write_disabled | TestWrite | 93 | null |
python-escpos/python-escpos | import types
import typing
import hypothesis.strategies as st
import pytest
from hypothesis import example, given
from escpos import printer
from escpos.exceptions import Error
from escpos.katakana import encode_katakana
from escpos.magicencode import Encoder, MagicEncode
class TestInit:
def test_disabl... | Error) | pytest.raises | variable | test/test_magicencode.py | test_disabled_requires_encoding | TestInit | 65 | null |
python-escpos/python-escpos | from typing import List
from escpos.image import EscposImage
def test_split() -> None:
"""
test whether the split-function works as expected
"""
im = EscposImage("test/resources/black_white.png")
(upper_part, lower_part) = im.split(1)
upper_part = EscposImage(upper_part)
lower_part = Escpo... | b"\xc0" | assert | string_literal | test/test_image.py | test_split | 61 | null | |
python-escpos/python-escpos | import pytest
from PIL import Image
import escpos.printer as printer
from escpos.exceptions import ImageWidthError
def test_graphics_both() -> None:
"""
Test printing black/white graphics
"""
instance = printer.Dummy()
instance.image("test/resources/black_white.png", impl="graphics")
assert | b"\x1d(L\x0c\x000p0\x01\x011\x02\x00\x02\x00\xc0\x00\x1d(L\x02\x0002" | assert | string_literal | test/test_functions/test_function_image.py | test_graphics_both | 132 | null | |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform == "win32", reason="skipping non Windows platform specific tests"
)
def test_open_raise_exception(lpprinter, devicenotfounderror, mocker):
"""
GIVEN a lp printer object
WHEN open() is set to raise a DeviceNotFoundEr... | devicenotfounderror) | pytest.raises | variable | test/test_printers/test_printer_lp.py | test_open_raise_exception | 41 | null | |
python-escpos/python-escpos | import barcode.errors
import pytest
import escpos.printer as printer
def instance():
return printer.Dummy()
def test_soft_barcode_ean8_invalid(instance: printer.Dummy) -> None:
"""test with an invalid barcode"""
with pytest.raises( | barcode.errors.BarcodeError) | pytest.raises | complex_expr | test/test_functions/test_function_softbarcode.py | test_soft_barcode_ean8_invalid | 16 | null | |
python-escpos/python-escpos | from escpos.printer import Dummy
def test_printer_dummy_clear() -> None:
printer = Dummy()
printer.text("Hello")
printer.clear()
assert printer.output == | b"" | assert | string_literal | test/test_functions/test_function_dummy_clear.py | test_printer_dummy_clear | 8 | null | |
python-escpos/python-escpos | import logging
import pytest
def test_device_not_initialized(networkprinter):
"""
GIVEN a network printer object
WHEN it is not initialized
THEN check the device property is False
"""
assert networkprinter._device is | False | assert | bool_literal | test/test_printers/test_printer_network.py | test_device_not_initialized | 22 | null | |
python-escpos/python-escpos | import pytest
import escpos.printer as printer
from escpos.exceptions import CashDrawerError
def test_raise_CashDrawerError() -> None:
"""should raise an error if the sequence is invalid."""
instance = printer.Dummy()
with pytest.raises( | CashDrawerError) | pytest.raises | variable | test/test_functions/test_function_cashdraw.py | test_raise_CashDrawerError | 12 | null | |
python-escpos/python-escpos | import pytest
from escpos.capabilities import BARCODE_B, NotSupported, Profile, get_profile
def profile():
return get_profile("default")
class TestBaseProfile:
def test_get_columns(self, profile):
assert profile.get_columns("a") > | 5 | assert | numeric_literal | test/test_profile.py | test_get_columns | TestBaseProfile | 25 | null |
python-escpos/python-escpos | import os
import shutil
import tempfile
from scripttest import TestFileEnvironment as TFE
import escpos
TEST_DIR = tempfile.mkdtemp() + "/cli-test"
DEVFILE_NAME = "testfile"
DEVFILE = os.path.join(TEST_DIR, DEVFILE_NAME)
CONFIGFILE = "testconfig.yaml"
CONFIG_YAML = f"""
---
printer:
type: file
devfile: {D... | result.files_updated.keys() | assert | func_call | test/test_cli.py | test_cli_text | TestCLI | 102 | null |
python-escpos/python-escpos | from typing import Optional
import pytest
import escpos.printer as printer
from escpos.constants import SET_FONT, TXT_NORMAL, TXT_SIZE, TXT_STYLE
from escpos.exceptions import SetVariableError
@pytest.mark.parametrize("width", [None, 0, 9, 10, 4444])
@pytest.mark.parametrize("height", [None, 0, 9, 10, 4444])
def tes... | SetVariableError) | pytest.raises | variable | test/test_functions/test_function_set.py | test_set_size_custom_invalid_input | 173 | null | |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform == "win32", reason="skipping non Windows platform specific tests"
)
def test_printers_no_device(cupsprinter) -> None:
"""
GIVEN a cups printer object
WHEN device is None
THEN check the return value is {}
"""... | {} | assert | collection | test/test_printers/test_printer_cups.py | test_printers_no_device | 166 | null | |
python-escpos/python-escpos | import pytest
def test_add_padding_into_cols(driver) -> None:
"""
GIVEN a list of strings
WHEN adding padding and different alignments to each string
THEN check the strings are correctly padded and aligned
"""
output = driver._add_padding_into_cols(
text_list=["col1", "col2", "col3", "... | [" col1 ", "col2 ", " col3", "col 4"] | assert | collection | test/test_functions/test_function_software_columns.py | test_add_padding_into_cols | 40 | null | |
python-escpos/python-escpos | import logging
import pytest
def test_device_not_initialized(fileprinter):
"""
GIVEN a file printer object
WHEN it is not initialized
THEN check the device property is False
"""
assert fileprinter._device is | False | assert | bool_literal | test/test_printers/test_printer_file.py | test_device_not_initialized | 22 | null | |
python-escpos/python-escpos | import escpos.printer as printer
def test_function_panel_button_off() -> None:
"""test the panel button function (disabling) by comparing output"""
instance = printer.Dummy()
instance.panel_buttons(False)
assert instance.output == | b"\x1B\x63\x35\x01" | assert | string_literal | test/test_functions/test_function_panel_button.py | test_function_panel_button_off | 25 | null | |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform != "win32", reason="Skipping Windows platform specific tests"
)
def test_open_not_raise_exception(win32rawprinter, caplog):
"""
GIVEN a win32raw printer object
WHEN open() is set to not raise on error but simply can... | None | assert | none_literal | test/test_printers/test_printer_win32raw.py | test_open_not_raise_exception | 55 | null | |
python-escpos/python-escpos | import pathlib
import platformdirs
import pytest
import escpos.exceptions
def generate_dummy_config(path, content=None):
"""Generate a dummy config in path"""
dummy_config_content = content
if not content:
dummy_config_content = "printer:\n type: Dummy\n"
path.write_text(dummy_config_conten... | escpos.exceptions.ConfigNotFoundError) | pytest.raises | complex_expr | test/test_config.py | test_config_load_with_missing_config | 70 | null | |
python-escpos/python-escpos | import escpos.printer as printer
def test_function_linedisplay_select_off() -> None:
"""test the linedisplay_select function (deactivate)"""
instance = printer.Dummy()
instance.linedisplay_select(select_display=False)
assert instance.output == | b"\x1B\x3D\x01" | assert | string_literal | test/test_functions/test_function_linedisplay.py | test_function_linedisplay_select_off | 25 | null | |
python-escpos/python-escpos | from typing import List
from escpos.image import EscposImage
def _load_and_check_img(
filename: str,
width_expected: int,
height_expected: int,
raster_format_expected: bytes,
column_format_expected: List[bytes],
) -> None:
"""
Load an image, and test whether raster & column formatted outpu... | column_format_expected[i] | assert | complex_expr | test/test_image.py | _load_and_check_img | 81 | null | |
python-escpos/python-escpos | import os
import shutil
import tempfile
from scripttest import TestFileEnvironment as TFE
import escpos
TEST_DIR = tempfile.mkdtemp() + "/cli-test"
DEVFILE_NAME = "testfile"
DEVFILE = os.path.join(TEST_DIR, DEVFILE_NAME)
CONFIGFILE = "testconfig.yaml"
CONFIG_YAML = f"""
---
printer:
type: file
devfile: {D... | result.stderr | assert | complex_expr | test/test_cli.py | test_cli_text_invalid_args | TestCLI | 115 | null |
python-escpos/python-escpos | import pytest
import escpos.printer as printer
from escpos.constants import QR_ECLEVEL_H, QR_MODEL_1
def test_invalid_ec() -> None:
"""Test invalid QR error correction"""
instance = printer.Dummy()
with pytest.raises( | ValueError) | pytest.raises | variable | test/test_functions/test_function_qr_native.py | test_invalid_ec | 71 | null | |
python-escpos/python-escpos | from abc import ABCMeta
import pytest
import escpos.escpos as escpos
def test_abstract_base_class() -> None:
"""test whether Escpos has the metaclass ABCMeta"""
assert issubclass(escpos.Escpos, object)
assert type(escpos.Escpos) is | ABCMeta | assert | variable | test/test_abstract_base_class.py | test_abstract_base_class | 27 | null | |
python-escpos/python-escpos | import logging
import pytest
def test_device_not_initialized(serialprinter):
"""
GIVEN a serial printer object
WHEN it is not initialized
THEN check the device property is False
"""
assert serialprinter._device is | False | assert | bool_literal | test/test_printers/test_printer_serial.py | test_device_not_initialized | 22 | null | |
python-escpos/python-escpos | import logging
import sys
import pytest
pytestmark = pytest.mark.skipif(
sys.platform != "win32", reason="Skipping Windows platform specific tests"
)
def test_open(win32rawprinter, caplog, mocker):
"""
GIVEN a win32raw printer object and a mocked win32printer device
WHEN a valid connection to a devic... | win32rawprinter.printers | assert | complex_expr | test/test_printers/test_printer_win32raw.py | test_open | 73 | null | |
python-escpos/python-escpos | import logging
import pytest
def test_open_not_raise_exception(serialprinter, caplog):
"""
GIVEN a serial printer object
WHEN open() is set to not raise on error but simply cancel
THEN check the error is logged and open() canceled
"""
serialprinter.devfile = "fake/device"
with caplog.at_l... | caplog.text | assert | complex_expr | test/test_printers/test_printer_serial.py | test_open_not_raise_exception | 48 | null | |
python-escpos/python-escpos | import pathlib
import platformdirs
import pytest
import escpos.exceptions
def generate_dummy_config(path, content=None):
"""Generate a dummy config in path"""
dummy_config_content = content
if not content:
dummy_config_content = "printer:\n type: Dummy\n"
path.write_text(dummy_config_conten... | escpos.exceptions.ConfigSyntaxError) | pytest.raises | complex_expr | test/test_config.py | test_config_load_with_invalid_config_yaml | 44 | null | |
python-escpos/python-escpos | import pytest
import escpos.printer as printer
from escpos.capabilities import BARCODE_B, Profile
from escpos.exceptions import BarcodeCodeError, BarcodeTypeError
@pytest.mark.parametrize(
"bctype,supports_b",
[
("invalid", True),
("CODE128", False),
],
)
def test_lacks_support(bctype, sup... | BarcodeTypeError) | pytest.raises | variable | test/test_functions/test_function_barcode.py | test_lacks_support | 38 | null | |
python-escpos/python-escpos | import types
import typing
import hypothesis.strategies as st
import pytest
from hypothesis import example, given
from escpos import printer
from escpos.exceptions import Error
from escpos.katakana import encode_katakana
from escpos.magicencode import Encoder, MagicEncode
class TestWriteWithEncoding:
def... | b"\x1bt\x13\xd5 ist teuro." | assert | string_literal | test/test_magicencode.py | test_init_from_none | TestWriteWithEncoding | 72 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.