def test_3(self): """ Add a second field to the filter """ Out.log('Adding a second field (value) to the filter') self.test_filter.add_constraint('Value','180') self.test_filter.add_constraint('Manufacturer','Vishay/Dale') matching_components = [] for comp in self.test_components: if self.test_filter.matches(comp): matching_components.append(comp) Out.log('Matching components: %s' % matching_components) assert(len(matching_components) == 1)
def test_2(self): """ Filter custom field manufacturer """ Out.log('Generating filter for a given manufacturer') self.test_filter = Filter() self.test_filter.add_constraint('Manufacturer','Vishay/Dale') matching_components = [] for comp in self.test_components: if self.test_filter.matches(comp): matching_components.append(comp) Out.log('Matching components: %s' % matching_components) assert(len(matching_components) == 5)
def add_or_update_field(self, name, value): """ Add a new (custom) field or replace an existing field """ # warn and return if name is empty if name == '': Out.warn('Will not add or update field in ' + self.get_field('Designator').value + ' due to empty name') return # log when clearing a value elif value == '': Out.log('Clearing value of field "' + name + '" in ' + self.get_field('Designator').value + '.') # change value of name-matching fields Out.fine('Changing value of fields matching the name "' + name + '"') for index, field in enumerate(self._fields): if field.name == name: Out.fine('Overwriting value of field #' + str(index) + ' with ' + name + ':' + value) self._fields[index].value = value # only designator and value should be visible if name == 'Designator' or name == 'Value': self._fields[index].set_visible(True) else: self._fields[index].set_visible(False) return # Construct and add new custom field new_field = CustomField.copy(self.get_field('Designator')) new_field.name = name new_field.value = value new_field.number = len(self._fields) new_field.set_visible(False) Out.fine('Adding new custom field:' + new_field.serialize()) self._fields.append(new_field)
def print_matches(self): """ Print all matching components """ Out.ok('Matching components:') for component in self.matching_components: Out.log(component)
def setUp(self): Out.log('Preparing components using schematic class') self.test_schematic = Schematic('test1.sch') self.test_components = self.test_schematic._components self.test_filter = Filter()