def test_parse(self): bad_input = [ 'YRUN\n', # Missing ^+ '+YRUN\n YRUN,', # Wrong separator 'YRUN; TOTO; TATA; TITI\n', # Wrong field count 'BADKW; TOTO; TATA\n', # Wrong kyeword name ] for content in bad_input: path = makeTempFile(content) ic = InstrumentConfig(path) self.assertRaises(ValueError, ic.parse) os.unlink(path) # Feeds in a valid entry to check output path = makeTempFile('YRUN; HIERARCH ESO OBS PROG ID; RUNID') ic = InstrumentConfig(path) map = ic.parse() self.assertTrue(map.has_key('YRUN')) self.assertTrue(map.has_key('+COPY')) self.assertTrue(len(map['+COPY']) == 0) for k in ('SRC', 'MAP'): self.assertTrue(map['YRUN'].has_key(k)) os.unlink(path) path = makeTempFile('YRUN; HIERARCH ESO OBS PROG ID') ic = InstrumentConfig(path) map = ic.parse() self.assertFalse(len(map['+COPY']) > 0) self.assertFalse(map['YRUN'].has_key('MAP')) os.unlink(path)
def setup_itt(): """ Check ingestion translations tables """ instrus = Instrument.objects.filter(Q(name = 'Megacam') | Q(name = 'Wircam')) for ins in instrus: ins.name = ins.name.upper() ins.save() itts = glob.glob(os.path.join(settings.TRUNK, 'terapix', 'lib', 'itt', 'conf', '*.conf')) for itt in itts: name = os.path.basename(itt)[:-5].upper() inst = Instrument.objects.filter(name = name) # Parse it and get dictionnary mapping ic = InstrumentConfig(itt) content = ic.parse() zcontent = base64.encodestring(zlib.compress(marshal.dumps(content), 9)).replace('\n', '') if inst: # Instrument already existing inst = inst[0] inst.itt = zcontent inst.save() logger.log("Updated ITT for instrument %s" % name) else: inst = Instrument(name = name, itt = zcontent) inst.save() logger.log("Added instrument %s and ITT" % name)