Ejemplo n.º 1
0
def test_function_same_module_same_source_stable():
    def another_foo_function():
        pass

    original = checksum(another_foo_function)

    def another_foo_function():
        pass

    redefined = checksum(another_foo_function)

    assert original == redefined
Ejemplo n.º 2
0
def test_function_source_changes():
    def another_foo_function():
        return 1

    return_1 = checksum(another_foo_function)

    def another_foo_function():
        return 2

    return_2 = checksum(another_foo_function)

    assert return_1 != return_2
Ejemplo n.º 3
0
def test_function_attributes_change_checksum():
    def foo1():
        pass

    before_attribute, no_change = checksum(foo1), checksum(foo1)
    foo1.version = 1
    after_attribute = checksum(foo1)
    foo1.version += 1
    changing_attribute = checksum(foo1)

    assert before_attribute == no_change, "Function checksum unstable"
    assert before_attribute != after_attribute, "Adding attribute should change checksum"
    assert changing_attribute != after_attribute, "Changing attribute should change checksum"
Ejemplo n.º 4
0
def main():
    """Example of using checksums to determine if the contents of a dict have changed """
    sub_dict = {1: 42, 2: 82}
    big_dict = {
        'a': sub_dict,
        'b': (6, 7, 8),
        'c': ['a', 'b', 'c'],
    }

    c_1 = checksum(big_dict)
    sub_dict[1] += 1
    c_2 = checksum(big_dict)

    # changing the contents of the dict changes the checksum
    assert c_1 != c_2

    sub_dict[1] -= 1
    c_3 = checksum(big_dict)

    # changing the contents back restores the original checksum
    assert c_1 == c_3
Ejemplo n.º 5
0
def test_depends_on_qsum_version():
    """Special test for qsum_version dep since the version isn't always available"""
    assert len(checksum(
        'abc', depends_on=DependsOn.QSumVer)) == DEFAULT_BYTES_IN_CHECKSUM
Ejemplo n.º 6
0
def test_depends_on_values(depends_on):
    """Simple test of DependsOn.PythonEnv that also validates depends_on support of single DependsOn enum values"""
    assert len(checksum('abc',
                        depends_on=depends_on)) == DEFAULT_BYTES_IN_CHECKSUM
Ejemplo n.º 7
0
def test_checksum_changes_with_dependency():
    """Validate that the checksum actually changes when we add a dep"""
    assert checksum(123, depends_on=('pytest', )) != checksum(123)
Ejemplo n.º 8
0
def local_foo_checksum():
    return checksum(foo_function)
Ejemplo n.º 9
0
def test_from_checksum():
    assert Checksum.from_checksum(
        checksum(CHECKSUM_CLASS_VALUE)) == EXPECTED_CHECKSUM
Ejemplo n.º 10
0
def test_checksum_class_checksum_bytes(checksum_class):
    assert checksum_class.checksum_bytes == checksum(CHECKSUM_CLASS_VALUE)
Ejemplo n.º 11
0
def test_checksum_types(value, expected_type):
    assert checksum_to_type(checksum(value)) == expected_type
Ejemplo n.º 12
0
def main():
    """Compute the checksum of a string and print it's hex"""
    print(checksum('abcd').hex())
Ejemplo n.º 13
0
def main():
    """main method"""
    long_list = list(range(0, 1000000))
    print(checksum(long_list).hex())
Ejemplo n.º 14
0
def foo_checksum():
    return checksum(foo_function)
Ejemplo n.º 15
0
def test_bytes_in_checksum(value):
    assert len(
        checksum(value)
    ) == DEFAULT_BYTES_IN_CHECKSUM, "Validate the number of bytes of the checksum"