def test_morse_to_text_strict(self): """Test morseovky na text s kontrolou mezer.""" translator = MorseCodeTranslator() morse = ".... . .-.. .-.. --- .-- --- .-. .-.. -.." expected_output = ("Chyba! Nalezeny 4 mezery ve stringu.") self.assertEqual(translator.translate_morse(morse, strict=True), expected_output)
def test_morse_to_text_strict(self): """Unit tests.""" translator = MorseCodeTranslator() morse = ".... . .-.. .-.. --- .-- --- .-. .-.. -.." expected_output = ("Unable to translate morse code.") self.assertEqual(translator.translate_morse(morse, strict=True), expected_output)
def test_morse_to_text_not_strict(self): """Test morseovky na text bez kontroly mezer.""" translator = MorseCodeTranslator() morse = ".... . .-.. .-.. --- .-- --- .-. .-.. -.." expected_output = "hello world" self.assertEqual(translator.translate_morse(morse, strict=False), expected_output)
def test_morse_to_text_not_strict(self): """Unit tests.""" translator = MorseCodeTranslator() morse = ".... . .-.. .-.. --- .-- --- .-. .-.. -.." expected_output = "hello world" self.assertEqual(translator.translate_morse(morse, strict=False), expected_output)
def test_morse_to_numbers(self): """Unit tests.""" translator = MorseCodeTranslator() morse = ".---- ..--- ...-- ....- ..... -.... --... ---.. ----. -----" expected_output = "1234567890" self.assertEqual(translator.translate_morse(morse), expected_output)
def test_morse_to_punctuation(self): """Test morseovky na znaky.""" translator = MorseCodeTranslator() morse = ".-... .----. .--.-. -.--.- -.--. ---... --..-- -...- -.-.--" expected_output = "&'@)(:,=!" self.assertEqual(translator.translate_morse(morse), expected_output)
#!/usr/bin/env python # -*- coding: utf-8 -*- from morse import MorseCodeTranslator from uuid import uuid4 from telegram import InlineQueryResultArticle, ParseMode, InputTextMessageContent from telegram.ext import Updater, InlineQueryHandler, CommandHandler from telegram.utils.helpers import escape_markdown import os from dotenv import load_dotenv load_dotenv() morse_code_translator = MorseCodeTranslator() welcome_message = """ *Welcome\!* To encode with Morse code, send: `@morse_inline_bot your\_message` To decode, send: `@morse_inline_bot m/-.-- --- ..- .-. -- . ... ... .- --. .` __Enjoy\!__ _P\.S\._ _You can find and use\(why'd you\) source code at [GitHub](https://github.com/slntopp/morse_inline_bot)_ """
def test_morse_to_text_no_morse(self): """Unit tests.""" translator = MorseCodeTranslator() morse = "" expected_output = "You must provide a string of text to translate" self.assertEqual(translator.translate_morse(morse), expected_output)
def test_text_to_morse_no_text(self): """Unit tests.""" translator = MorseCodeTranslator() text = "" expected_output = "You must provide a morse code string to translate" self.assertEqual(translator.translate_text(text), expected_output)
def test_morse_to_text2(self): """Unit tests.""" translator = MorseCodeTranslator() morse = "12 & 4 56 7+8" x = ".---- ..--- .-... ....- ..... -.... --... .-.-. ---.." self.assertEqual(translator.translate_text(morse), x)
def test_all_to_morse(self): """Test kombinace symbolu na morseovku.""" translator = MorseCodeTranslator() text = "1h+" expected_output = ".---- .... .-.-." self.assertEqual(translator.translate_text(text), expected_output)
def test_morse_to_text_no_morse(self): """Test na prazdny vstup.""" translator = MorseCodeTranslator() morse = "" expected_output = "Musite vlozit string na preklad!" self.assertEqual(translator.translate_morse(morse), expected_output)
def test_punctuation_to_morse(self): """Test znaku na morseovku.""" translator = MorseCodeTranslator() text = "&'@)(:," expected_output = ".-... .----. .--.-. -.--.- -.--. ---... --..--" self.assertEqual(translator.translate_text(text), expected_output)
def test_numbers_to_morse(self): """Test cisel na morsovku.""" translator = MorseCodeTranslator() text = "12345678" expected_output = ".---- ..--- ...-- ....- ..... -.... --... ---.." self.assertEqual(translator.translate_text(text), expected_output)
def test_morse_to_punctuation1(self): """Unit tests.""" translator = MorseCodeTranslator() morse = ".----. ---... --..-- .-.-.- .-..-. -..-." x = "':,.\"/" self.assertEqual(translator.translate_morse(morse), x)
def test_punctuation_to_morse1(self): """Unit tests.""" translator = MorseCodeTranslator() text = "':,.\"/" x = ".----. ---... --..-- .-.-.- .-..-. -..-." self.assertEqual(translator.translate_text(text), x)
def test_all_to_morse(self): """Unit tests.""" translator = MorseCodeTranslator() text = "Hello world.." x = ".... . .-.. .-.. --- .-- --- .-. .-.. -.. .-.-.- .-.-.-" self.assertEqual(translator.translate_text(text), x)
def test_morse_to_text1(self): """Unit tests.""" translator = MorseCodeTranslator() morse = "!<testing>!?" x = "-.-.-- - . ... - .. -. --. -.-.-- ..--.." self.assertEqual(translator.translate_text(morse), x)
def test_all_to_morse1(self): """Unit tests.""" translator = MorseCodeTranslator() text = "12 & 4 56 7+8" x = ".---- ..--- .-... ....- ..... -.... --... .-.-. ---.." self.assertEqual(translator.translate_text(text), x)
def test_morse_to_text3(self): """Unit tests.""" translator = MorseCodeTranslator() morse = "(this) is?" x = "-.--. - .... .. ... -.--.- .. ... ..--.." self.assertEqual(translator.translate_text(morse), x)
def test_all_to_morse2(self): """Unit tests.""" translator = MorseCodeTranslator() text = "(this) is?" x = "-.--. - .... .. ... -.--.- .. ... ..--.." self.assertEqual(translator.translate_text(text), x)
def test_text_to_morse(self): """Unit tests.""" translator = MorseCodeTranslator() text = "hello world" expected_output = ".... . .-.. .-.. --- .-- --- .-. .-.. -.." self.assertEqual(translator.translate_text(text), expected_output)
def test_all_to_morse3(self): """Unit tests.""" translator = MorseCodeTranslator() text = "'Just' @#,.:" x = ".----. .--- ..- ... - .----. .--.-. --..-- .-.-.- ---..." self.assertEqual(translator.translate_text(text), x)
def test_numbers_to_morse(self): """Unit tests.""" translator = MorseCodeTranslator() text = "1234567890" exp_out = ".---- ..--- ...-- ....- ..... -.... --... ---.. ----. -----" self.assertEqual(translator.translate_text(text), exp_out)
def test_all_to_morse4(self): """Unit tests.""" translator = MorseCodeTranslator() text = "!<testing>!?" x = "-.-.-- - . ... - .. -. --. -.-.-- ..--.." self.assertEqual(translator.translate_text(text), x)
"""Modul pro spousteni kodu.""" from morse import MorseCodeTranslator if __name__ == "__main__": translator = MorseCodeTranslator() text = input("Zadej string na preklad do morseovky a zpet: ") # Prelozi text do morseovky morse = translator.translate_text(text) # Prelozi morseovku na text translated_text = translator.translate_morse(morse) print(morse) print(translated_text)
def test_morse_to_text(self): """Test morseovky na text.""" translator = MorseCodeTranslator() morse = ".... . .-.. .-.. --- .-- --- .-. .-.. -.." expected_output = "hello world" self.assertEqual(translator.translate_morse(morse), expected_output)