def test_long_alphabet() -> None: """Test that a long alphabet does throw an error.""" alphabet = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "2", "3", "4", "5", "6", "7", "?", "@", "=", ] with pytest.raises(BadAlphabetException): Damm32(alphabet)
def test_bad_letter_in_alphabet() -> None: """Test that a bad letter in the alphabet does throw an error.""" alphabet = [ "AAAAA", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "2", "3", "4", "5", "6", "7", "?", "@", ] with pytest.raises(BadCharacterException): Damm32(alphabet)
def test_valid_alphabet() -> None: """Test that a valid alphabet does not throw an error.""" alphabet = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "2", "3", "4", "5", "6", "7", ] Damm32(alphabet)
#! /usr/bin/env python from damm32 import Damm32 d32 = Damm32() org = "SRO" code = input("Enter asset code: ") print(d32.verify(org + code.upper()))
def test_accepts_string() -> None: """Test that the calculate method accepts a string.""" d32 = Damm32() d32.calculate("STRING")
def test_rejects_not_string() -> None: """Test that the calculate method rejects other types.""" d32 = Damm32() with pytest.raises(TypeError): d32.calculate(3) # type: ignore
def test_empty_string() -> None: """Test empty strings.""" d32 = Damm32() assert d32.verify("") assert d32.calculate("") == 'A'
def __init__(self) -> None: self._d32 = Damm32() self._alphabet = self._d32._alphabet self._prefix = settings.PYINV_ASSET_CODE_PREFIX
def test_class_instantiation() -> None: """Test that the class instantiates to an instance of Damm32.""" d32 = Damm32() assert isinstance(d32, Damm32)
def test_default_alphabet() -> None: """Test that the default alphabet does not throw an error.""" Damm32()
def test_to_word_non_standard_alphabet() -> None: """Test that the _to_word function works.""" d32 = Damm32(list("BACDEFGHIJKLMNOPQSTUVWXYZ1234567")) digit_list = [1, 2, 3, 4, 5, 1, 3, 1, 3, 3, 9, 15, 31] assert d32._to_word(digit_list) == "ACDEFADADDJP7" assert type(d32._to_word(digit_list)) is str
def test_to_word() -> None: """Test that the _to_word function works.""" d32 = Damm32() digit_list = [1, 2, 3, 4, 5, 1, 3, 1, 3, 3, 9, 15, 31] assert d32._to_word(digit_list) == "BCDEFBDBDDJP7" assert type(d32._to_word(digit_list)) is str
def test_bad_letter_detected() -> None: """Test that a bad letter throws an error.""" with pytest.raises(BadCharacterException): d32 = Damm32() d32.calculate("?@")
def test_empty_alphabet() -> None: """Test that an empty alphabet does throw an error.""" with pytest.raises(BadAlphabetException): Damm32([])