Пример #1
0
 def code(self):
     code = "\n".join([pcb.header(), pcb.setup(), ""])
     if not self.events:
         code += "   ;\n"
     else:
         code += "\n".join([event.codeblock
                            for event in self.events] + [""])
     code += pcb.end()
     return code
Пример #2
0
 def test_non_int_trigger(self):
     with self.assertRaises(TypeError):
         codeblocks.setup(triggered=True, parameter=3.14)
     with self.assertRaises(TypeError):
         codeblocks.setup(triggered=True, parameter="four")
     with self.assertRaises(TypeError):
         codeblocks.setup(triggered=True, parameter="12e-1")
Пример #3
0
 def test_default_trig(self):
     """Test that `codeblocks.setup(triggered=True)` behaves correctly.
     """
     correct = "void setup() {\n" \
               "   for (int i=1; i<=78; i++)\n" \
               "      detachInterrupt(i);\n" \
               "   void __disable_irq(void);\n" \
               f"   REG_PIOC_OER = {config.all_pins_enabled};\n" \
               f"   REG_PIOC_OWER = {config.all_pins_enabled};\n" \
               f"   attachInterrupt({config.trigger_pin}, " \
                                    "sequence, RISING);\n" \
               "}\n\n" \
               "void sequence() {"
     self.assertEqual(codeblocks.setup(triggered=True), correct,
                      "The default setup code block for trig. mode" \
                      "is incorrect.")
Пример #4
0
 def test_delay_point_zero_conversion(self):
     """Test that ints represented as floats like 4.0 are accepted.
     """
     correct = "void setup() {\n" \
               "   for (int i=1; i<=78; i++)\n" \
               "      detachInterrupt(i);\n" \
               "   void __disable_irq(void);\n" \
               f"   REG_PIOC_OER = {config.all_pins_enabled};\n" \
               f"   REG_PIOC_OWER = {config.all_pins_enabled};\n" \
               "   while(1) {\n" \
               "      sequence();\n" \
               "      delay(4);\n" \
               "   }\n" \
               "}\n\n" \
               "void sequence() {"
     self.assertEqual(
         codeblocks.setup(triggered=False, parameter=4.0), correct,
         "Conversion of integer-like float 4.0 to int failed.")
Пример #5
0
 def test_default_cont(self):
     """Test that `codeblocks.setup(triggered=False)` behaves correctly.
     """
     correct = "void setup() {\n" \
               "   for (int i=1; i<=78; i++)\n" \
               "      detachInterrupt(i);\n" \
               "   void __disable_irq(void);\n" \
               f"   REG_PIOC_OER = {config.all_pins_enabled};\n" \
               f"   REG_PIOC_OWER = {config.all_pins_enabled};\n" \
               "   while(1) {\n" \
               "      sequence();\n" \
               f"      delay({config.cont_mode_delay_ms});\n" \
               "   }\n" \
               "}\n\n" \
               "void sequence() {"
     self.assertEqual(codeblocks.setup(triggered=False), correct,
                      "The default setup code block for cont. mode" \
                      "is incorrect.")
Пример #6
0
 def test_no_input(self):
     """Test that `codeblocks.setup()` produces setup for continuously
     running pulsebox with the default delay.
     """
     correct = "void setup() {\n" \
               "   for (int i=1; i<=78; i++)\n" \
               "      detachInterrupt(i);\n" \
               "   void __disable_irq(void);\n" \
               f"   REG_PIOC_OER = {config.all_pins_enabled};\n" \
               f"   REG_PIOC_OWER = {config.all_pins_enabled};\n" \
               "   while(1) {\n" \
               "      sequence();\n" \
               f"      delay({config.cont_mode_delay_ms});\n" \
               "   }\n" \
               "}\n\n" \
               "void sequence() {"
     self.assertEqual(codeblocks.setup(), correct,
                      "The default setup code block is incorrect.")
Пример #7
0
    def test_delay_scientific_conversion(self):
        """Test that integers in scientific notation like 1e2 are accepted.
        """

        correct = "void setup() {\n" \
                  "   for (int i=1; i<=78; i++)\n" \
                  "      detachInterrupt(i);\n" \
                  "   void __disable_irq(void);\n" \
                  f"   REG_PIOC_OER = {config.all_pins_enabled};\n" \
                  f"   REG_PIOC_OWER = {config.all_pins_enabled};\n" \
                  "   while(1) {\n" \
                  "      sequence();\n" \
                  "      delay(100);\n" \
                  "   }\n" \
                  "}\n\n" \
                  "void sequence() {"
        self.assertEqual(
            codeblocks.setup(triggered=False, parameter=1e2), correct,
            "Conversion of integer-like float 1e2 to int failed.")
Пример #8
0
 def test_overlapping_trigger(self):
     """See that trigger pin cannot be identical to a pulsebox pin.
     """
     for pin in config.pulsebox_pins:
         with self.assertRaises(ValueError):
             codeblocks.setup(triggered=True, parameter=pin)
Пример #9
0
 def test_invalid_trigger_pin(self):
     with self.assertRaises(ValueError):
         codeblocks.setup(triggered=True, parameter=-1)
     with self.assertRaises(ValueError):
         codeblocks.setup(triggered=True, parameter=79)
Пример #10
0
 def test_non_32bit_delay(self):
     with self.assertRaises(ValueError):
         codeblocks.setup(triggered=False, parameter=-1)
     with self.assertRaises(ValueError):
         codeblocks.setup(triggered=False, parameter=2**32)