Ejemplo n.º 1
0
 def test_extract_expression(self):
     for fragment, expect in (
         ('if condition(x):',     'condition(x)'),
         ('elif is_magic(name):', 'is_magic(name)'),
         ('while expression:',    'expression'),
         ('for i in range(3):',   'range(3)'),
         ('abc = 123',            '123'),
         ('return return_value',  'return_value'),
         ('nothing_to_be.done',   'nothing_to_be.done'), ):
         self.assertEqual(expect , Meval.extract_expression(fragment))
         pass
     pass
Ejemplo n.º 2
0
 def test_extract_expression(self):
     for fragment, expect in (
         ('if condition(x):', 'condition(x)'),
         ('elif is_magic(name):', 'is_magic(name)'),
         ('while expression:', 'expression'),
         ('for i in range(3):', 'range(3)'),
         ('abc = 123', '123'),
         ('assert True', 'True'),
         ('return return_value', 'return_value'),
         ('nothing_to_be.done', 'nothing_to_be.done'),
     ):
         self.assertEqual(expect, Meval.extract_expression(fragment))
         pass
     pass
Ejemplo n.º 3
0
 def test_extract_expression(self):
     for fragment, expect in (
         ("if condition(x):", "condition(x)"),
         ("elif is_magic(name):", "is_magic(name)"),
         ("while expression:", "expression"),
         ("for i in range(3):", "range(3)"),
         ("and x > 3", "x > 3"),
         ("or y < 3", "y < 3"),
         ("abc = 123", "123"),
         ("assert True", "True"),
         ("return return_value", "return_value"),
         ("nothing_to_be.done", "nothing_to_be.done"),
     ):
         self.assertEqual(expect, Meval.extract_expression(fragment))
         pass
     pass
Ejemplo n.º 4
0
    def run(self, args):
        if 1 == len(args):
            text = self.proc.current_source_text.rstrip('\n')
            if '?' == args[0][-1]:
                text = Meval.extract_expression(text)
                self.msg("eval: %s" % text)
                pass

        else:
            text = self.proc.current_command[len(self.proc.cmd_name):]
            pass
        text = text.strip()
        try:
            self.proc.exec_line(text)
        except:
            pass
Ejemplo n.º 5
0
 def run(self, args):
     if 1 == len(args):
         if self.proc.current_source_text:
             text = self.proc.current_source_text.rstrip('\n')
             if '?' == args[0][-1]:
                 text = Meval.extract_expression(text)
                 self.msg("eval: %s" % text)
                 pass
         else:
             self.errmsg("Don't have find program source text")
             return
     else:
         text = self.proc.current_command[len(self.proc.cmd_name):]
         pass
     text = text.strip()
     try:
         self.proc.exec_line(text)
     except:
         pass