示例#1
0
def main():
    """Checksums can be combined"""
    object_1 = {'a': [1, 2, 3]}
    object_2 = {'b': [4, 5, 6]}

    c_1 = Checksum(object_1)
    c_2 = Checksum(object_2)

    combined = c_1 + c_2

    print(combined)
示例#2
0
def main():
    obj = {
        'a': list(range(1, 100)),
        1: random.random(),
        (5, 7): {0.1, 0.2, 0.3},
        1.5: frozenset({1, 2, 3}),
        'd':
        (foo_function, foo_function2),  # tuple of functions, getting fun ha?
        'random': random,  # yes the entire module,
    }
    check = Checksum(obj)
    print(
        check.hex()
    )  # this will change between python versions since we're checksumming the random module
示例#3
0
def test_checksum_class_init():
    checksum_is_checksum = functools.partial(Checksum, is_checksum=True)

    # three types of checksum objects supported
    checksums = list(
        map(checksum_is_checksum, (
            Checksum('foo'),
            '00012c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae',
            b'\x00\x01,&\xb4kh\xff\xc6\x8f\xf9\x9bE<\x1d0A4\x13B-pd\x83\xbf\xa0\xf9\x8a^\x88bf\xe7\xae'
        )))

    assert checksums[0].checksum_bytes == checksums[
        1].checksum_bytes == checksums[2].checksum_bytes
示例#4
0
def test_checksum_add_order_dependent():
    assert Checksum(1) + Checksum(2) + Checksum(3) != Checksum(3) + Checksum(
        2) + Checksum(1)
示例#5
0
def test_checksum_add():
    checksum_collection = Checksum(1) + Checksum(2)
    assert checksum_collection.hex(
    ) == 'ff1112e56c5e7ba9ec2ddd13fc983287f720eb103312bf3536480af0f7dfef255a12'
    assert checksum_to_type(
        checksum_collection.checksum_bytes) == ChecksumCollection
示例#6
0
def test_checksum_non_checksum_like_object():
    Checksum(1, is_checksum=True)
示例#7
0
def test_checksum_not_eq(checksum_class):
    assert Checksum(CHECKSUM_CLASS_VALUE + 1).hex() != checksum_class
示例#8
0
def test_checksum_eq(checksum_class):
    assert checksum_class == Checksum(CHECKSUM_CLASS_VALUE)
    assert Checksum(CHECKSUM_CLASS_VALUE).hex() == checksum_class
    assert Checksum(CHECKSUM_CLASS_VALUE).checksum_bytes == checksum_class
示例#9
0
def test_expected_custom_type():
    _ = Checksum.checksum(Custom()).type
示例#10
0
def test_checksum_class_eq(checksum_class):
    assert checksum_class == Checksum.checksum(CHECKSUM_CLASS_VALUE)
示例#11
0
def checksum_class():
    return Checksum(CHECKSUM_CLASS_VALUE)
示例#12
0
文件: helpers.py 项目: nerohmot/qsum
# pylint: disable=too-few-public-methods,missing-function-docstring
import pytest

from qsum import Checksum, checksum

STR_CHECKSUM_OBJS = [
    Checksum('123'),
    '0001a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3',
    bytes.fromhex(
        '0001a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3')
]
INT_CHECKSUM_OBJS = [
    Checksum(123),
    '0000a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3',
    bytes.fromhex(
        '0000a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3')
]


@pytest.fixture(scope='session')
def range_2_16():
    """Create a range fixture for use in pytests"""
    return range(-2**16, 2**16)


class Custom:
    """A Custom class to try and checksum"""


class CustomDict1(dict):
    """A Custom Class that inherits from dict"""
示例#13
0
def test_expected_checksum(value, expected_checksum):
    checksum_bytes = Checksum.checksum(value).hex()
    assert checksum_bytes == expected_checksum, "Got '{}'\nExpected '{}' for the checksum of '{}'".format(
        checksum_bytes, expected_checksum, value)
示例#14
0
def test_expected_type(obj_type, value):
    assert type(value) == Checksum.checksum(value).type == obj_type
示例#15
0
def main():
    with_versions = Checksum("abc", depends_on=('wheel', 'setuptools'))
    print(with_versions.hex())
示例#16
0
def test_from_checksum():
    assert Checksum.from_checksum(
        checksum(CHECKSUM_CLASS_VALUE)) == EXPECTED_CHECKSUM
示例#17
0
def test_dependency_original_type():
    """Ensure we get the original type right even if adding depends_on"""
    assert Checksum('abc', depends_on=('pytest', )).type == str
示例#18
0
def main():
    my_custom_dict = CustomDict()
    my_custom_dict['b'] = 1
    my_custom_dict['a'] = 2

    print(Checksum(my_custom_dict).hex())