Example #1
0
 def test_zero_entries(self):
     fields_def = OrderedDict([('text', {'len': 0}), ('empty', {'len': 0}), ('number', {'len': 6,
                                                                                        'decoder': decode_int,
                                                                                        'encoder': encode_int
                                                                                        })])
     fields = {'text': 'testfilename', 'number': 0}
     smrtf = SmartFilename(fields, fields_def, ext='.tif', compact=True)
     self.assertEqual(str(smrtf), 'testfilename__0.tif')
     smrtf_fn = SmartFilename.from_filename('fromfilename__0.tif', fields_def=fields_def, compact=True, convert=True)
     self.assertEqual(smrtf_fn['number'], 0)
Example #2
0
    def test_variable_length_fields(self):
        """
        Test if required delimiter for field with variable length is detected.
        """
        self.fields_def.update({'variable': {'len': 0, 'delim': ''}})

        fields = {'pflag': 'M', 'dtime_1': '20180101120000'}
        with self.assertRaises(ValueError):
            smrtf = SmartFilename(fields, self.fields_def)

        fn = 'M_20180101120000.tif'
        with self.assertRaises(ValueError):
            smrtf = SmartFilename.from_filename(fn, self.fields_def)