Beispiel #1
0
 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)
Beispiel #2
0
 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)
Beispiel #3
0
 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)
Beispiel #4
0
 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)
Beispiel #5
0
 def test_morse_to_numbers(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     morse = ".---- ..--- ...-- ....- ..... -.... --... ---.. ----. -----"
     expected_output = "1234567890"
     self.assertEqual(translator.translate_morse(morse), expected_output)
Beispiel #6
0
 def test_morse_to_punctuation(self):
     """Test morseovky na znaky."""
     translator = MorseCodeTranslator()
     morse = ".-... .----. .--.-. -.--.- -.--. ---... --..-- -...- -.-.--"
     expected_output = "&'@)(:,=!"
     self.assertEqual(translator.translate_morse(morse), expected_output)
Beispiel #7
0
#!/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)_
"""
Beispiel #8
0
 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)
Beispiel #9
0
 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)
Beispiel #10
0
 def test_morse_to_text2(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     morse = "12 & 4 56 7+8"
     x = ".---- ..---   .-...   ....-   ..... -....   --... .-.-. ---.."
     self.assertEqual(translator.translate_text(morse), x)
Beispiel #11
0
 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)
Beispiel #12
0
 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)
Beispiel #13
0
 def test_punctuation_to_morse(self):
     """Test znaku na morseovku."""
     translator = MorseCodeTranslator()
     text = "&'@)(:,"
     expected_output = ".-... .----. .--.-. -.--.- -.--. ---... --..--"
     self.assertEqual(translator.translate_text(text), expected_output)
Beispiel #14
0
 def test_numbers_to_morse(self):
     """Test cisel na morsovku."""
     translator = MorseCodeTranslator()
     text = "12345678"
     expected_output = ".---- ..--- ...-- ....- ..... -.... --... ---.."
     self.assertEqual(translator.translate_text(text), expected_output)
Beispiel #15
0
 def test_morse_to_punctuation1(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     morse = ".----. ---... --..-- .-.-.- .-..-. -..-."
     x = "':,.\"/"
     self.assertEqual(translator.translate_morse(morse), x)
Beispiel #16
0
 def test_punctuation_to_morse1(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     text = "':,.\"/"
     x = ".----. ---... --..-- .-.-.- .-..-. -..-."
     self.assertEqual(translator.translate_text(text), x)
Beispiel #17
0
 def test_all_to_morse(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     text = "Hello world.."
     x = ".... . .-.. .-.. ---   .-- --- .-. .-.. -.. .-.-.- .-.-.-"
     self.assertEqual(translator.translate_text(text), x)
Beispiel #18
0
 def test_morse_to_text1(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     morse = "!<testing>!?"
     x = "-.-.-- - . ... - .. -. --. -.-.-- ..--.."
     self.assertEqual(translator.translate_text(morse), x)
Beispiel #19
0
 def test_all_to_morse1(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     text = "12 & 4 56 7+8"
     x = ".---- ..---   .-...   ....-   ..... -....   --... .-.-. ---.."
     self.assertEqual(translator.translate_text(text), x)
Beispiel #20
0
 def test_morse_to_text3(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     morse = "(this) is?"
     x = "-.--. - .... .. ... -.--.-   .. ... ..--.."
     self.assertEqual(translator.translate_text(morse), x)
Beispiel #21
0
 def test_all_to_morse2(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     text = "(this) is?"
     x = "-.--. - .... .. ... -.--.-   .. ... ..--.."
     self.assertEqual(translator.translate_text(text), x)
Beispiel #22
0
 def test_text_to_morse(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     text = "hello world"
     expected_output = ".... . .-.. .-.. ---   .-- --- .-. .-.. -.."
     self.assertEqual(translator.translate_text(text), expected_output)
Beispiel #23
0
 def test_all_to_morse3(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     text = "'Just' @#,.:"
     x = ".----. .--- ..- ... - .----.   .--.-. --..-- .-.-.- ---..."
     self.assertEqual(translator.translate_text(text), x)
Beispiel #24
0
 def test_numbers_to_morse(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     text = "1234567890"
     exp_out = ".---- ..--- ...-- ....- ..... -.... --... ---.. ----. -----"
     self.assertEqual(translator.translate_text(text), exp_out)
Beispiel #25
0
 def test_all_to_morse4(self):
     """Unit tests."""
     translator = MorseCodeTranslator()
     text = "!<testing>!?"
     x = "-.-.-- - . ... - .. -. --. -.-.-- ..--.."
     self.assertEqual(translator.translate_text(text), x)
Beispiel #26
0
"""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)
Beispiel #27
0
 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)