Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 4
0
def test_checksum_add_order_dependent():
    assert Checksum(1) + Checksum(2) + Checksum(3) != Checksum(3) + Checksum(
        2) + Checksum(1)
Exemplo n.º 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
Exemplo n.º 6
0
def test_checksum_non_checksum_like_object():
    Checksum(1, is_checksum=True)
Exemplo n.º 7
0
def test_checksum_not_eq(checksum_class):
    assert Checksum(CHECKSUM_CLASS_VALUE + 1).hex() != checksum_class
Exemplo n.º 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
Exemplo n.º 9
0
def test_expected_custom_type():
    _ = Checksum.checksum(Custom()).type
Exemplo n.º 10
0
def test_checksum_class_eq(checksum_class):
    assert checksum_class == Checksum.checksum(CHECKSUM_CLASS_VALUE)
Exemplo n.º 11
0
def checksum_class():
    return Checksum(CHECKSUM_CLASS_VALUE)
Exemplo n.º 12
0
# 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"""
Exemplo n.º 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)
Exemplo n.º 14
0
def test_expected_type(obj_type, value):
    assert type(value) == Checksum.checksum(value).type == obj_type
Exemplo n.º 15
0
def main():
    with_versions = Checksum("abc", depends_on=('wheel', 'setuptools'))
    print(with_versions.hex())
Exemplo n.º 16
0
def test_from_checksum():
    assert Checksum.from_checksum(
        checksum(CHECKSUM_CLASS_VALUE)) == EXPECTED_CHECKSUM
Exemplo n.º 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
Exemplo n.º 18
0
def main():
    my_custom_dict = CustomDict()
    my_custom_dict['b'] = 1
    my_custom_dict['a'] = 2

    print(Checksum(my_custom_dict).hex())