def setUp(self): """ An instance of :class:`~lofarpipe.support.lofaringredient.LOFARingredient` is defined which contains three instances of :class:`~lofarpipe.support.lofaringredient.StringField`. """ from lofarpipe.support.lofaringredient import StringField from lofarpipe.support.lofaringredient import LOFARingredient f = StringField(default="foo") g = StringField() h = StringField(default=1) self.lofaringredient = LOFARingredient({"f": f, "g": g, "h": h})
class example(BaseRecipe): inputs = { 'executable': ExecField('--executable', help="Command to run", default="/bin/ls") } outputs = {'stdout': StringField()} def go(self): self.logger.info("Starting example recipe run") super(example, self).go() self.logger.info("This is a log message") my_process = subprocess.Popen([self.inputs['executable']], stdout=subprocess.PIPE, stderr=subprocess.PIPE) sout, serr = communicate_returning_strings(my_process) self.outputs['stdout'] = sout log_process_output(self.inputs['executable'], sout, serr, self.logger) if my_process.returncode == 0: return 0 else: self.logger.warn("Return code (%d) is not 0." % my_process.returncode) return 1
class StringFieldTest(unittest.TestCase): """ Tests for :class:`lofarpipe.support.lofaringredient.StringField` """ def setUp(self): from lofarpipe.support.lofaringredient import StringField self.stringfield = StringField(default="a string") def test_validator(self): """ Check that strings are correctly regarded as valid, and integers aren't. """ self.assertFalse(self.stringfield.is_valid(1)) self.assertTrue(self.stringfield.is_valid("1")) def test_default(self): """ Check that default is correctly set. """ self.assertEqual(self.stringfield.default, "a string")
def setUp(self): from lofarpipe.support.lofaringredient import StringField self.stringfield = StringField(default="a string")