Пример #1
0
    def test_enum_dups(self):
	self.assert_enum_has_no_duplicates(Command)
	self.assert_enum_has_no_duplicates(SubMenu)
	self.assert_enum_has_no_duplicates(ProtocolState)
	self.assert_enum_has_no_duplicates(ProtocolEvent)
	self.assert_enum_has_no_duplicates(Capability)
	self.assert_enum_has_no_duplicates(Parameter)
	self.assert_enum_has_no_duplicates(VisibleParameters)
	self.assert_enum_has_no_duplicates(BarsDataParticleKey)

	capability = convert_enum_to_dict(Capability)
	event = convert_enum_to_dict(ProtocolEvent)
	cmd = convert_enum_to_dict(Command)
	cmd_char = COMMAND_CHAR
	param = convert_enum_to_dict(Parameter)
	viz = convert_enum_to_dict(VisibleParameters)
	
	self.assert_set_complete(capability, event)
	self.assert_set_complete(cmd_char, cmd)
	self.assert_set_complete(viz, param)
Пример #2
0
    def assert_enum_has_no_duplicates(self, obj):
        dic = convert_enum_to_dict(obj)
        occurances  = {}
        for k, v in dic.items():
            #v = tuple(v)
            occurances[v] = occurances.get(v,0) + 1

        for k in occurances:
            if occurances[k] > 1:
                log.error(str(obj) + " has ambigous duplicate values for '" + str(k) + "'")
                self.assertEqual(1, occurances[k])
Пример #3
0
    def test_enum_dups(self):
        self.assert_enum_has_no_duplicates(Command)
        self.assert_enum_has_no_duplicates(SubMenu)
        self.assert_enum_has_no_duplicates(ProtocolState)
        self.assert_enum_has_no_duplicates(ProtocolEvent)
        self.assert_enum_has_no_duplicates(Capability)
        self.assert_enum_has_no_duplicates(Parameter)
        self.assert_enum_has_no_duplicates(VisibleParameters)
        self.assert_enum_has_no_duplicates(BarsDataParticleKey)

        capability = convert_enum_to_dict(Capability)
        event = convert_enum_to_dict(ProtocolEvent)
        cmd = convert_enum_to_dict(Command)
        cmd_char = COMMAND_CHAR
        param = convert_enum_to_dict(Parameter)
        viz = convert_enum_to_dict(VisibleParameters)

        self.assert_set_complete(capability, event)
        self.assert_set_complete(cmd_char, cmd)
        self.assert_set_complete(viz, param)
Пример #4
0
    def test_convert_enum_to_dict(self):
        """
        Test convert enum to dict method
        """
        class MyEnum(BaseEnum):
            FOO = 1
            BAR = 2

        dict = convert_enum_to_dict(MyEnum);

        self.assertEqual(dict.get('FOO'), MyEnum.FOO)
        self.assertEqual(dict.get('BAR'), MyEnum.BAR)
        self.assertEqual(len(dict), 2)
Пример #5
0
    def test_convert_enum_to_dict(self):
        """
        Test convert enum to dict method
        """
        class MyEnum(BaseEnum):
            FOO = 1
            BAR = 2

        dict = convert_enum_to_dict(MyEnum)

        self.assertEqual(dict.get('FOO'), MyEnum.FOO)
        self.assertEqual(dict.get('BAR'), MyEnum.BAR)
        self.assertEqual(len(dict), 2)
Пример #6
0
    def assert_sample_data_particle(self, particle):
	"""
	Assert that a parsed structure is valid
	@param particle A dict representation of a data particle structure or a
	JSON string that can be turned into one.
	"""
	if (isinstance(particle, BarsDataParticle)):
            sample_dict = json.loads(particle.generate_parsed())
        else:
            sample_dict = particle
	
	self.assert_v1_particle_headers(sample_dict)
        
	# now for the individual values
	for x in sample_dict['values']:
            self.assertTrue(x['value_id'] in convert_enum_to_dict(BarsDataParticleKey).values())
            log.debug("ID: %s value: %s type: %s" % (x['value_id'], x['value'], type(x['value'])))
            self.assertTrue(isinstance(x['value'], float))
Пример #7
0
    def assert_sample_data_particle(self, particle):
        """
	Assert that a parsed structure is valid
	@param particle A dict representation of a data particle structure or a
	JSON string that can be turned into one.
	"""
        if isinstance(particle, BarsDataParticle):
            sample_dict = json.loads(particle.generate_parsed())
        else:
            sample_dict = particle

        self.assert_v1_particle_headers(sample_dict)

        # now for the individual values
        for x in sample_dict["values"]:
            self.assertTrue(x["value_id"] in convert_enum_to_dict(BarsDataParticleKey).values())
            log.debug("ID: %s value: %s type: %s" % (x["value_id"], x["value"], type(x["value"])))
            self.assertTrue(isinstance(x["value"], float))