def test_name_set_no_changes(self): """ Tests that the field name does not change for creating a new one """ field1 = basic.numeric_float(4, 2, name='field1') field2 = basic.numeric_float(4, 2, name='field2') self.assertEqual('field1', field1.name) self.assertEqual('field2', field2.name)
def percentage(columns, maximum=100, name=None): """ Creates the grammar for a Numeric (N) field storing a percentage and accepting only the specified number of characters. It is possible to set the maximum allowed value. By default this is 100 (for 100%), and if modified it is expected to be reduced, not increased. The three first digits will be for the integer value. The columns can't be lower than 3. :param columns: number of columns for this field :param maximum: maximum allowed value :param name: name for the field :return: grammar for the float numeric field """ if name is None: name = 'Percentage Field' if columns < 3: message = 'The values can not be lower than 3' raise pp.ParseException(message) field = basic.numeric_float(columns, 3) field.addParseAction(lambda v: _assert_is_percentage(v[0], maximum)) field.setName(name) return field
def test_name_default(self): """ Tests that the default field name is correct for optional fields. """ field = basic.numeric_float(4, 2) self.assertEqual('Numeric Field', field.name)
def test_name_default_compulsory(self): """ Tests that the default field name is correct for optional fields, for compulsory fields. """ field = basic.numeric_float(4, 2, compulsory=True) self.assertEqual('Numeric Field', field.name)
def test_name_set(self): """ Tests that the given field name is set correctly for optional fields. """ name = "Field Name" field = basic.numeric_float(4, 2, name=name) self.assertEqual(name, field.name)
def get_field(self, name=None, columns=None, values=None): if values is not None and len(values) > 0: nums_int = int(values[0]) else: nums_int = columns return basic.numeric_float(columns=columns, nums_int=nums_int, name=name)
def setUp(self): self.num = basic.numeric_float(5, 3)
""" if len(parsed) > 0: return 2000 + parsed[0] else: return None # Sender sender = pp.Word(pp.alphanums, min=2, max=3) sender = sender.setName('Sender').setResultsName('sender') # Receiver receiver = pp.Word(pp.alphanums, min=2, max=3) receiver = receiver.setName('Received').setResultsName('receiver') # Version number version_num = basic.numeric_float(2, 1) version_num = version_num.setName('Version').setResultsName('version') """ Delimiters. These divide the distinct sections of the filename, and mostly can be ignored. The only special case is if this is a zip file. In that case the extension will be parsed as if it were the version node, but will return the default version. """ # Filename header header = pp.CaselessLiteral('CW') header.suppress() header.setName('Filename Header')
def setUp(self): self.num = basic.numeric_float(5, 3, compulsory=True)