Exemplo n.º 1
0
 def __init__(
         self,
         time_cost=40,
         memory_cost=128000,
         parallelism=2,
         encoding="utf-8",
         hash_len=1024,  # 22 for 31 characters
         salt=b"5\xca\xfa\xb7\x1a'\x00!\xe6Ys\x1d~M\x00o",
         salt_len=16):
     salt_len = len(salt)
     e = _check_types(
         time_cost=(time_cost, int),
         memory_cost=(memory_cost, int),
         parallelism=(parallelism, int),
         hash_len=(hash_len, int),
         salt_len=(salt_len, int),
         salt=(salt, bytes),
         encoding=(encoding, str),
     )
     if e:
         raise TypeError(e)
     self.time_cost = time_cost
     self.memory_cost = memory_cost
     self.parallelism = parallelism
     self.hash_len = hash_len
     self.salt_len = salt_len
     self.salt = salt
     self.encoding = encoding
Exemplo n.º 2
0
 def test_success(self):
     """
     Returns None if all types are okay.
     """
     assert None is _check_types(
         bytes=(b"bytes", bytes),
         tuple=((1, 2), tuple),
         str_or_None=(None, (str, NoneType)),
     )
Exemplo n.º 3
0
 def test_success(self):
     """
     Returns None if all types are okay.
     """
     assert None is _check_types(
         bytes=(b"bytes", bytes),
         tuple=((1, 2), tuple),
         str_or_None=(None, (str, NoneType)),
     )
Exemplo n.º 4
0
    def test_fail(self):
        """
        Returns summary of failures.
        """
        rv = _check_types(
            bytes=("not bytes", bytes), str_or_None=(42, (str, NoneType))
        )

        assert "." == rv[-1]  # proper grammar FTW
        assert "'str_or_None' must be a str, or NoneType (got int)" in rv

        assert "'bytes' must be a bytes (got str)" in rv
Exemplo n.º 5
0
    def test_fail(self):
        """
        Returns summary of failures.
        """
        rv = _check_types(
            bytes=(u"not bytes", bytes),
            str_or_None=(42, (str, NoneType))
        )

        assert "." == rv[-1]  # proper grammar FTW
        assert "'str_or_None' must be a str, or NoneType (got int)" in rv

        if PY3:
            assert "'bytes' must be a bytes (got str)" in rv
        else:
            assert "'bytes' must be a str (got unicode)" in rv