Ejemplo n.º 1
0
 def test_translate_line(self):
     for key, val in TRANSLATE_LINE.items():
         duck = Converter()
         if isinstance(val, Exception):
             self.assertRaises(Exception, duck.translate_line, key)
         else:
             self.assertEqual(duck.translate_line(key), val)
Ejemplo n.º 2
0
    def test_translate_line_repeat(self):
        duck = Converter()
        self.assertRaises(ValueError, duck.translate_line, 'REPEAT 2')

        duck.translate_line('STRING abcdef')

        self.assertRaises(ValueError, duck.translate_line, 'REPEAT a')
        self.assertRaises(ValueError, duck.translate_line, 'REPEAT -2')

        self.assertEqual(
            duck.translate_line('REPEAT 2'), '''
for (int _repeat = 0; _repeat < 2; _repeat++)
{
    kbd_print("abcdef");
}''')
        self.assertEqual(duck.translate_line('REPEAT'), 'kbd_print("abcdef");')

        duck.translate_line('DEFAULT_DELAY 125')
        self.assertEqual(
            duck.translate_line('REPEAT 2'), '''
for (int _repeat = 0; _repeat < 2; _repeat++)
{
    kbd_print("abcdef");
    delay(125);
}''')
Ejemplo n.º 3
0
    def test_convert_to_file(self):
        duck = Converter()
        for root, _, files in os.walk(CONVERT_DATA_DIR):
            for fname in files:
                if not fname.endswith('.txt'):
                    continue

                fname = os.path.join(root, fname)
                fname_result = fname[:-4] + '.ino'

                with open(fname, 'r') as file, open(fname_result,
                                                    'r') as file_res:
                    out_stream = io.StringIO()
                    duck.convert_to_file(file, out_stream)
                    out_stream.seek(0)

                    self.assertEqual(out_stream.read(), file_res.read())
Ejemplo n.º 4
0
 def test_translate_line_flash_macro(self):
     duck = Converter(flash_macro=True)
     self.assertEqual(duck.translate_line('STRING abcdef'),
                      'kbd_print(F("abcdef"));')
Ejemplo n.º 5
0
 def test_translate_line_default_delay(self):
     duck = Converter()
     duck.translate_line('DEFAULT_DELAY 125')
     self.assertEqual(duck.global_delay, 125)
Ejemplo n.º 6
0
 def test_get_key_from_str_teensy(self):
     duck = Converter(convert_type=duckyconvert.TYPE_TEENSY)
     for key, val in GET_KEY_FROM_STR_TEENSY.items():
         self.assertEqual(duck.get_key_from_str(key), val)
Ejemplo n.º 7
0
 def test_get_key_from_str(self):
     duck = Converter()
     for key, val in GET_KEY_FROM_STR.items():
         self.assertEqual(duck.get_key_from_str(key), val)
Ejemplo n.º 8
0
 def test_type_string(self):
     duck = Converter()
     for entry in TYPE_STRING:
         self.assertEqual(duck.type_string(entry[STRING], entry[MODIFIERS]),
                          entry[RESULT])