def test_init_error(): """Test __init__ error""" with pytest.raises(Exception) as excinfo: tree = Coder() # pylint: disable=no-value-for-parameter, unused-variable exception_message = excinfo.value.args[0] assert (exception_message == "__init__() missing 1 required positional argument: 'file_in'")
def test_encode_error(the_tree: Coder, text: str, symbol: str): """Test encoding error""" with pytest.raises(ValueError) as excinfo: the_tree.encode(text) exception_message = excinfo.value.args[0] assert exception_message == f"Could not encode {text}: {symbol} is not in the tree"
def test_encode(the_tree: Coder, text: str, code: str): """Test encoding""" assert the_tree.encode(text) == code
def test_find_path_error(the_tree: Coder, letter: str): """Test find_path error""" assert not the_tree.find_path(the_tree.morse_tree, letter, "")
def test_find_path(the_tree: Coder, letter: str, code: str): """Test find_path""" assert the_tree.find_path(the_tree.morse_tree, letter, "") == code
def test_follow_and_retrieve_error(the_tree: Coder, code: str): """Test follow_and_retrieve error""" with pytest.raises(ValueError) as excinfo: the_tree.follow_and_retrieve(code) exception_message = excinfo.value.args[0] assert exception_message == f"Could not find {code} in the tree"
def test_follow_and_retrieve(the_tree: Coder, code: str, letter: str): """Test follow_and_retrieve""" assert the_tree.follow_and_retrieve(code) == letter
def test_follow_and_insert(the_tree: Coder, code: str, letter: str): """Test follow_and_insert""" the_tree.follow_and_insert(code, letter) assert the_tree.follow_and_retrieve(code) == letter
def test_init(): """Test __init__ error""" the_coder = Coder("data/projects/morse/morse.txt") assert isinstance(the_coder, Coder)
def the_tree(): """Setting up""" return Coder("data/projects/morse/morse.txt")
def test_decode_error(the_tree: Coder, code: str, symbol: str): """Test decoding error""" with pytest.raises(ValueError) as excinfo: the_tree.decode(code) exception_message = excinfo.value.args[0] assert exception_message == f"Could not decode {code}: {symbol} is not in the tree"
def test_decode(the_tree: Coder, code: str, text: str): """Test decode""" assert the_tree.decode(code) == text
def setup_class(self): """Setting up""" self.the_tree = Coder("data/projects/morse/morse.txt")
class TestMorseMethods: """Testing module morse""" @pytest.fixture(scope="function", autouse=True) def setup_class(self): """Setting up""" self.the_tree = Coder("data/projects/morse/morse.txt") def test_init_error(self): """Test __init__ error""" with pytest.raises(Exception) as excinfo: tree = Coder() # pylint: disable=no-value-for-parameter, unused-variable exception_message = excinfo.value.args[0] assert ( exception_message == "__init__() missing 1 required positional argument: 'file_in'" ) def test_find_path(self): """Test find_path""" assert self.the_tree.find_path(self.the_tree.morse_tree, "e", "") == "." assert not self.the_tree.find_path(self.the_tree.morse_tree, "$", "") def test_follow_and_retrieve(self): """Test follow_and_retrieve""" assert self.the_tree.follow_and_retrieve("-.-.") == "c" assert self.the_tree.follow_and_retrieve("...") == "s" assert not self.the_tree.follow_and_retrieve("-.-..") == "ć" assert not self.the_tree.follow_and_retrieve("...-...") == "ś" def test_follow_and_insert(self): """Test follow_and_insert""" self.the_tree.follow_and_insert("-.-..", "ć") assert self.the_tree.follow_and_retrieve("-.-..") == "ć" self.the_tree.follow_and_insert("...-...", "ś") assert self.the_tree.follow_and_retrieve("...-...") == "ś" def test_follow_and_insert_replacement(self): """Test follow_and_insert with replacement""" self.the_tree.follow_and_insert(".", "CS160") assert self.the_tree.follow_and_retrieve(".") == "CS160" assert not self.the_tree.follow_and_retrieve(".") == "e" def test_encode(self): """Test encoding""" assert self.the_tree.encode("sos") == "... --- ... " def test_encode_error(self): """Test encoding error""" with pytest.raises(ValueError) as excinfo: self.the_tree.encode("$$") exception_message = excinfo.value.args[0] assert exception_message == "Could not encode $$: $ is not in the tree" def test_decode(self): """Test decode""" assert self.the_tree.decode("... --- ...") == "sos" def test_decode_error(self): """Test decoding error""" with pytest.raises(ValueError) as excinfo: self.the_tree.decode("...---...") exception_message = excinfo.value.args[0] assert ( exception_message == "Could not decode ...---...: ...---... is not in the tree" )