File: test_types.py

package info (click to toggle)
devpi-common 3.2.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 248 kB
  • sloc: python: 1,552; makefile: 4
file content (24 lines) | stat: -rw-r--r-- 795 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

from devpi_common.types import *

def test_CompareMixin():
    class A(CompareMixin):
        def __init__(self, count):
            self.cmpval = count
    l = list(map(A, range(10)))
    assert max(reversed(l)).cmpval == 9


def test_parsehashspec():
    hash_algo, hash_value = parse_hash_spec("l1kj23")
    assert hash_algo is None and hash_value is None
    hash_algo, hash_value = parse_hash_spec("xyz=123098123")
    assert hash_algo is None and hash_value is None

    digest = hashlib.md5(b'123').hexdigest()
    hash_algo, hash_value = parse_hash_spec("md5=" + digest)
    assert hash_algo(b'123').hexdigest() == digest

    digest = hashlib.sha256(b'123').hexdigest()
    hash_algo, hash_value = parse_hash_spec("sha256=" + digest)
    assert hash_algo(b'123').hexdigest() == digest