Beispiel #1
0
    def test_mini_pac_bad_json(self):
        """ Test that bad json configurations fail against the mini-pac schema """

        # Macro entry
        bad_config_file = os.path.join(
            git_project_root(), 'tests/test-data/mini-pac-macro-bad.json')
        self.assertTrue(os.path.exists(bad_config_file))

        with open(bad_config_file) as h:
            bad_config = json.loads(h.read())

        with self.assertRaises(ValidationError):
            validate(bad_config, self.mini_pac_schema)

        # Pin entry
        bad_config_file = os.path.join(
            git_project_root(), 'tests/test-data/mini-pac-pin-bad.json')
        self.assertTrue(os.path.exists(bad_config_file))

        with open(bad_config_file) as h:
            bad_config = json.loads(h.read())

        with self.assertRaises(ValidationError):
            validate(bad_config, self.mini_pac_schema)

        # Debounce entry
        bad_config_file = os.path.join(
            git_project_root(), 'tests/test-data/mini-pac-debounce-bad.json')
        self.assertTrue(os.path.exists(bad_config_file))

        with open(bad_config_file) as h:
            bad_config = json.loads(h.read())

        with self.assertRaises(ValidationError):
            validate(bad_config, self.mini_pac_schema)
Beispiel #2
0
    def setUp(self) -> None:
        """ This is called before every test method in the test class """
        super(MiniPacDeviceTest, self).setUp()

        schema_file = os.path.join(git_project_root(), 'ultimarc/schemas/mini-pac.schema')
        self.assertTrue(os.path.exists(schema_file))
        config_file = os.path.join(git_project_root(), 'ultimarc/examples/mini-pac.json')
        self.assertTrue(os.path.exists(config_file))

        # https://python-jsonschema.readthedocs.io/en/stable/
        with open(schema_file) as h:
            self.mini_pac_schema = json.loads(h.read())
        with open(config_file) as h:
            self.mini_pac_config = json.loads(h.read())
    def setUp(self) -> None:
        """ This is called before every test method in the test class. """
        super(USBButtonSchemaTest, self).setUp()

        schema_file = os.path.join(git_project_root(),
                                   'ultimarc/schemas/usb-button-color.schema')
        self.assertTrue(os.path.exists(schema_file))
        config_file = os.path.join(git_project_root(),
                                   'ultimarc/examples/usb-button-color.json')
        self.assertTrue(os.path.exists(config_file))

        # https://python-jsonschema.readthedocs.io/en/stable/
        with open(schema_file) as h:
            self.color_schema = json.loads(h.read())
        with open(config_file) as h:
            self.color_config = json.loads(h.read())
Beispiel #4
0
    def test_mini_pac_large_macro_entries(self, dev_handle_mock, lib_usb_mock):
        """ Test that faults happen when the number of macros is to great
        and the number of actions doesn't exceed 85 with control characters """
        dev = USBDeviceHandle('test_handle', '0000:0000')
        self.assertTrue(dev)
        dev.__class__ = MiniPacDevice

        config_file = os.path.join(git_project_root(), 'tests/test-data/mini-pac-macro-large-count.json')
        valid, data = dev._create_message_(config_file)
        self.assertFalse(valid)
        self.assertIsNone(data)

        config_file = os.path.join(git_project_root(), 'tests/test-data/mini-pac-macro-large-action-count.json')
        valid, data = dev._create_message_(config_file)
        self.assertFalse(valid)
        self.assertIsNone(data)
    def test_validate_config_base(self, dev_handle_mock, lib_usb_mock):
        """ Test the validate_config_base() method of the USBDeviceHandle object. """

        dev = USBDeviceHandle('test_handle', '0000:0000')
        self.assertTrue(dev)

        config_file = os.path.join(
            git_project_root(), 'tests/test-data/usb-button-color-good.json')
        self.assertTrue(
            dev.validate_config_base(config_file, ['usb-button-color']))
        self.assertIsNone(
            dev.validate_config_base(config_file, ['bad-resource-type']))

        config_file = os.path.join(
            git_project_root(), 'tests/test-data/usb-button-color-bad.json')
        self.assertIsNone(
            dev.validate_config_base(config_file, ['usb-button-color']))
    def test_all_schemas(self):
        """
        Test all example JSON configuration files against base.schema.
        """
        schema_file = os.path.join(git_project_root(),
                                   'ultimarc/schemas/base.schema')
        self.assertTrue(os.path.exists(schema_file))
        # https://python-jsonschema.readthedocs.io/en/stable/
        with open(schema_file) as h:
            schema = json.loads(h.read())

        path = os.path.join(git_project_root(), 'ultimarc/examples/')
        files = glob(os.path.join(path, "*.json"))
        for file in files:
            with open(file) as h:
                config = json.loads(h.read())
            self.assertIsNone(validate(config, schema))
Beispiel #7
0
    def test_mini_pac_optional_json(self):
        """ Test validation when optional entries are not present """
        # Macro entry
        opt_config_file = os.path.join(
            git_project_root(), 'tests/test-data/mini-pac-pin-optional.json')
        self.assertTrue(os.path.exists(opt_config_file))

        with open(opt_config_file) as h:
            opt_config = json.loads(h.read())

        self.assertIsNone(validate(opt_config, self.mini_pac_schema))
Beispiel #8
0
    def test_mini_pac_pin_optional_params(self, dev_handle_mock, lib_usb_mock):
        """ Test that optional parameters are handled correctly """
        dev = USBDeviceHandle('test_handle', '0000:0000')
        self.assertTrue(dev)

        dev.__class__ = MiniPacDevice

        config_file = os.path.join(git_project_root(), 'tests/test-data/mini-pac-pin-optional.json')
        valid, data = dev._create_message_(config_file)

        # pin 1up values, has both optional values
        self.assertTrue(data.bytes[10] == 0x52)
        self.assertTrue(data.bytes[60] == 0x35)
        self.assertTrue(data.bytes[110] == 0x40)

        # pin 1sw2 values no optional values
        self.assertTrue(data.bytes[11] == 0x72)
        self.assertTrue(data.bytes[61] == 0)
        self.assertTrue(data.bytes[111] == 0)

        # macros
        self.assertTrue(data.bytes[166] == 0)
Beispiel #9
0
    def test_mini_pac_data_population (self, dev_handle_mock, lib_usb_mock):
        """ Test that data is being populated correctly when writing to device from json config """
        dev = USBDeviceHandle('test_handle', '0000:0000')
        self.assertTrue(dev)

        dev.__class__ = MiniPacDevice

        config_file = os.path.join(git_project_root(), 'tests/test-data/mini-pac-good.json')
        valid, data = dev._create_message_(config_file)
        #print(data)
        self.assertTrue(valid)
        self.assertIsNotNone(data)

        # header
        self.assertTrue(data.header.type == 0x50)
        self.assertTrue(data.header.byte_2 == 0xdd)
        self.assertTrue(data.header.byte_3 == 0x0f)
        self.assertTrue(data.header.byte_4 == 0)

        # pins
        # prep work check
        self.assertTrue(data.bytes[16] == 0xff)
        self.assertTrue(data.bytes[32] == 0x00)
        self.assertTrue(data.bytes[34] == 0x00)
        self.assertTrue(data.bytes[49] == 0xff)
        self.assertTrue(data.bytes[50] == 0x0)
        self.assertTrue(data.bytes[108] == 0x01)
        self.assertTrue(data.bytes[147] == 0x01)

        # pin 2b values
        self.assertTrue(data.bytes[0] == 0x29)
        self.assertTrue(data.bytes[50] == 0x0)
        self.assertTrue(data.bytes[100] == 0x0)

        # pin 1down values
        self.assertTrue(data.bytes[8] == 0x51)
        self.assertTrue(data.bytes[58] == 0x13)

        # pin 1left shift value
        self.assertTrue(data.bytes[112] == 0x40)

        # pin 2sw1 use macro in action
        self.assertTrue(data.bytes[17] == 0xe0)

        # pin 2sw2 use macro in alternate action
        self.assertTrue(data.bytes[69] == 0xe1)

        # Macros
        # macro #1
        self.assertTrue(data.bytes[166] == 0xe0)
        self.assertTrue(data.bytes[167] == 0x16)
        self.assertTrue(data.bytes[168] == 0x04)
        self.assertTrue(data.bytes[169] == 0x05)

        # macro #2
        self.assertTrue(data.bytes[170] == 0xe1)
        self.assertTrue(data.bytes[171] == 0x10)
        self.assertTrue(data.bytes[172] == 0x1f)

        # macro #3
        self.assertTrue(data.bytes[173] == 0xe2)
        self.assertTrue(data.bytes[174] == 0x10)
        self.assertTrue(data.bytes[175] == 0x20)
        self.assertTrue(data.bytes[176] == 0x10)
        self.assertTrue(data.bytes[177] == 0x20)
        self.assertTrue(data.bytes[178] == 0x1f)
        self.assertTrue(data.bytes[179] == 0x1e)

        # macro #4 (Is macro #5 in the configuration file)
        self.assertTrue(data.bytes[180] == 0xe3)
        self.assertTrue(data.bytes[181] == 0x10)
        self.assertTrue(data.bytes[182] == 0x1e)

        for x in range(183, 252):
            self.assertTrue(data.bytes[x] == 0)