Esempio n. 1
0
 def testPrintActionWithObjNoArg(self):
     c = self.CreateStringIOConsole()
     self.mox.StubOutWithMock(c, 'Print')
     c.Print('\x1b[32m', '[   HOGE   ]', '\x1b[0m', ' ', 'name', foo='bar')
     self.mox.ReplayAll()
     c.PrintAction('HOGE', struct.Struct(fullname='name'), foo='bar')
     self.mox.VerifyAll()
Esempio n. 2
0
 def testPrintActionWithObj(self):
     c = self.CreateStringIOConsole()
     c.Print = mock.MagicMock()
     c.PrintAction('HOGE', struct.Struct(fullname='name'),
                   'hoge', 'piyo', foo='bar')
     c.Print.assert_called_once_with(
         '\x1b[32m', '[   HOGE   ]', '\x1b[0m', ' ', 'name', ':', ' ',
         'hoge', 'piyo', foo='bar')
Esempio n. 3
0
 def test_print_action_with_obj_no_arg(self):
     c = self.create_stringio_console()
     c.Print = mock.MagicMock()
     c.PrintAction('HOGE', struct.Struct(fullname='name'), foo='bar')
     c.Print.assert_called_once_with('\x1b[32m',
                                     '[   HOGE   ]',
                                     '\x1b[0m',
                                     ' ',
                                     'name',
                                     foo='bar')
Esempio n. 4
0
    def test_do_clean(self):
        ui = mock.MagicMock()
        ui.options = struct.Struct({'skip_clean': False})

        task = self.project.HtmlifyFull(ui)
        while task.Continue():
            pass

        self.project.Test.called_once_with(ui)
        self.project.Clean.called_once_with(ui)
Esempio n. 5
0
    def test_skip_clean(self):
        ui = mock.MagicMock()
        ui.options = struct.Struct({'skip_clean': True})

        task = self.project.WikifyFull(ui)
        while task.Continue():
            pass

        self.project.Clean.assert_not_called()
        self.project.Test.assert_called_once_with(ui)
Esempio n. 6
0
    def test_do_clean(self):
        ui = mock.MagicMock()
        ui.options = struct.Struct({'skip_clean': False})
        project = markdownify_full.Project('project', 'base_dir', None)
        project.problems = []
        project.Clean = mock.MagicMock()

        task_graph = project._GenerateMarkdownFull(ui)
        task_graph.Continue()

        project.Clean.called_once_with(ui)
Esempio n. 7
0
    def test_skip_clean(self):
        ui = mock.MagicMock()
        ui.options = struct.Struct({'skip_clean': True})
        project = htmlify_full.Project('project', 'base_dir', None)
        project.problems = []
        project.Clean = mock.MagicMock()

        task_graph = project._GenerateHtmlFull(ui)
        task_graph.Continue()

        project.Clean.assert_not_called()
Esempio n. 8
0
 def testConsoleBase(self):
     c = console.ConsoleBase(out=None,
                             caps=struct.Struct(color=False,
                                                overwrite=False))
     self.assertEqual(c.BOLD, '')
     self.assertEqual(c.UP, '')
     c = console.ConsoleBase(out=None,
                             caps=struct.Struct(color=True,
                                                overwrite=False))
     self.assertNotEqual(c.BOLD, '')
     self.assertEqual(c.UP, '')
     c = console.ConsoleBase(out=None,
                             caps=struct.Struct(color=False,
                                                overwrite=True))
     self.assertEqual(c.BOLD, '')
     self.assertNotEqual(c.UP, '')
     c = console.ConsoleBase(out=None,
                             caps=struct.Struct(color=True, overwrite=True))
     self.assertNotEqual(c.BOLD, '')
     self.assertNotEqual(c.UP, '')
Esempio n. 9
0
 def _GetCaps(cls):
     caps = struct.Struct()
     caps.overwrite = False
     caps.color = False
     if sys.stdout.isatty():
         try:
             import curses
             curses.setupterm()
             caps.overwrite = bool(curses.tigetstr('cuu1'))
             caps.color = bool(curses.tigetstr('setaf'))
         except:
             pass
     return caps
Esempio n. 10
0
def LoadRequiredModules():
    # TODO(nya): Fix this hacky implementation.
    module_loader.LoadPackage('rime.basic')
    while True:
        commands = commands_mod.GetCommands()
        default_options = struct.Struct(commands[None].GetDefaultOptionDict())
        null_console = console_mod.NullConsole()
        graph = taskgraph.SerialTaskGraph()
        fake_ui = ui_mod.UiContext(default_options, null_console, commands,
                                   graph)
        try:
            LoadProject(os.getcwd(), fake_ui)
            break
        except targets.ConfigurationError:
            # Configuration errors should be processed later.
            break
        except targets.ReloadConfiguration:
            # Processed use_plugin(). Retry.
            pass
Esempio n. 11
0
 def test_add_attr(self):
     s = struct.Struct()
     s.test_attr = 'test_obj'
     self.assertEqual(s.test_attr, 'test_obj')
Esempio n. 12
0
 def test_attribute_error(self):
     s = struct.Struct()
     with self.assertRaises(AttributeError):
         s.test_attr
Esempio n. 13
0
 def test_constructor(self):
     s = struct.Struct(test_attr='test_obj')
     self.assertEqual(s.test_attr, 'test_obj')
     self.assertEqual(s['test_attr'], 'test_obj')
Esempio n. 14
0
def Parse(argv, commands):
    """Parses the command line arguments.

    Arguments:
      argv: A list of string passed to the command.
          Note that this should include sys.argv[0] as well.

    Returns:
      A tuple of (cmd_name, extra_args, options) where:
        cmd: Command object of the main command specified by the command line.
        extra_args: A list of extra arguments given to the command.
        options: Struct containing option arguments.

    Raises:
      ParseError: When failed to parse arguments.
    """
    default = commands[None]
    cmd = None
    extra_args = []
    options = default.GetDefaultOptionDict()

    assert len(argv) >= 1
    i = 1
    option_finished = False

    while i < len(argv):
        arg = argv[i]
        i += 1

        if option_finished or not arg.startswith('-'):
            if cmd is None:
                arg = arg.lower()

                if arg not in commands:
                    raise ParseError('Unknown command: %s' % arg)
                cmd = commands[arg]
                options.update(cmd.GetDefaultOptionDict())

            else:
                extra_args.append(arg)

        else:
            longopt = arg.startswith('--')
            optvalue = None

            if longopt:
                optname = arg[2:]
                if optname == '':
                    option_finished = True
                    continue
                if '=' in optname:
                    sep = optname.find('=')
                    optvalue = optname[sep + 1:]
                    optname = optname[:sep]
                optnames = [optname]

            else:
                optnames = arg[1:]

            for optname in optnames:
                optfull = '%s%s' % (longopt and '--' or '-', optname)

                option = (cmd and cmd.FindOptionEntry(optname) or
                          default.FindOptionEntry(optname))
                if option is None:
                    raise ParseError('Unknown option: %s' % optfull)

                if option.argtype is bool:
                    optvalue = True
                elif optvalue is None:
                    if i == len(argv):
                        raise ParseError(
                            'Option parameter was missing for %s' % optfull)
                    optvalue = argv[i]
                    i += 1

                try:
                    optvalue = option.argtype(optvalue)
                except Exception:
                    raise ParseError(
                        'Invalid option parameter for %s' % optfull)

                options[option.varname] = optvalue

    if cmd is None:
        cmd = commands[None]
        options['help'] = True

    return (cmd, extra_args, struct.Struct(options))
Esempio n. 15
0
 def __init__(self):
     null_caps = struct.Struct(color=False, overwrite=False)
     super(NullConsole, self).__init__(files.OpenNull(), null_caps)
Esempio n. 16
0
 def test_add_key(self):
     s = struct.Struct()
     s['test_attr'] = 'test_obj'
     self.assertEqual(s.test_attr, 'test_obj')
     self.assertEqual(s['test_attr'], 'test_obj')
Esempio n. 17
0
 def CreateStringIOConsole(self):
     return console.ConsoleBase(out=StringIO(),
                                caps=struct.Struct(color=True,
                                                   overwrite=True))