コード例 #1
0
ファイル: test_plugin.py プロジェクト: zeldigas/ofxstatement
    def test_get_plugin_conflict(self) -> None:
        ep = mock.Mock()

        ep_patch = mock.patch("pkg_resources.iter_entry_points", return_value=[ep, ep])
        with ep_patch:
            with self.assertRaises(plugin.PluginNameConflict):
                plugin.get_plugin("conflicting", mock.Mock("UI"), mock.Mock("Settings"))
コード例 #2
0
    def test_get_plugin_conflict(self):
        ep = mock.Mock()

        ep_patch = mock.patch("pkg_resources.iter_entry_points",
                              return_value=[ep, ep])
        with ep_patch:
            with self.assertRaises(plugin.PluginNameConflict):
                plugin.get_plugin("conflicting", None, None)
コード例 #3
0
ファイル: tool.py プロジェクト: bubbas/ofxstatement
def process(args, ui):
    # read configuration
    config = configuration.read(ui)

    if args.type not in config:
        raise Abort("No section named %s in config file" % args.type)

    settings = config[args.type]

    pname = settings.get('plugin', None)
    if not pname:
        raise Abort("Specify 'plugin' setting for section %s" % args.type)

    # pick and configure plugin 
    try:
        p = plugin.get_plugin(pname, ui, settings)
    except plugin.PluginNotRegistered as e:
        raise Abort("No plugin named '%s' is found" % e) from e

    # process the input and produce output
    parser = p.get_parser(args.input)
    statement = parser.parse()

    with open(args.output, "w") as out:
        writer = OfxWriter(statement)
        out.write(writer.toxml())

    ui.status("Conversion completed: %s" % args.input)
コード例 #4
0
def convert(args: argparse.Namespace) -> int:
    appui = ui.UI()
    config = configuration.read()

    if config is None:
        # No configuration mode
        settings = {}
        pname = args.type
    else:
        # Configuration is loaded
        if args.type not in config:
            log.error("No section '%s' in config file." % args.type)
            log.error(
                "Edit configuration using ofxstatement edit-config and "
                "add section [%s]." % args.type
            )
            return 1  # error

        settings = dict(config[args.type])

        pname = settings.get("plugin", None)
        if not pname:
            log.error("Specify 'plugin' setting for section [%s]" % args.type)
            return 1  # error

    # pick and configure plugin
    try:
        p = plugin.get_plugin(pname, appui, settings)
    except plugin.PluginNotRegistered:
        log.error("No plugin named '%s' is found" % pname)
        return 1  # error

    # process the input and produce output
    parser = p.get_parser(args.input)
    try:
        statement = parser.parse()
    except exceptions.ParseError as e:
        log.error("Parse error on line %s: %s" % (e.lineno, e.message))
        return 2  # parse error

    # Validate the statement
    try:
        statement.assert_valid()
    except exceptions.ValidationError as e:
        log.error("Statement validation error: %s" % (e.message))
        return 2  # Validation error

    with smart_open(args.output, settings.get("encoding", None)) as out:
        writer = ofx.OfxWriter(statement)
        out.write(writer.toxml())

    log.info("Conversion completed: %s" % args.input)
    return 0  # success
コード例 #5
0
ファイル: test_plugin.py プロジェクト: zeldigas/ofxstatement
    def test_get_plugin(self) -> None:
        class SamplePlugin(plugin.Plugin):
            def get_parser(self):
                return mock.Mock()

        ep = mock.Mock()
        ep.load.return_value = SamplePlugin

        ep_patch = mock.patch("pkg_resources.iter_entry_points", return_value=[ep])

        with ep_patch:
            p = plugin.get_plugin("sample", mock.Mock("UI"), mock.Mock("Settings"))
            self.assertIsInstance(p, SamplePlugin)
コード例 #6
0
    def test_get_plugin(self):
        class SamplePlugin(plugin.Plugin):
            def get_parser(self):
                return mock.Mock()

        ep = mock.Mock()
        ep.load.return_value = SamplePlugin

        ep_patch = mock.patch("pkg_resources.iter_entry_points",
                              return_value=[ep])

        with ep_patch:
            p = plugin.get_plugin("sample", None, None)
            self.assertIsInstance(p, SamplePlugin)
コード例 #7
0
ファイル: tool.py プロジェクト: mcpat/ofxstatement
def convert(args):
    appui = ui.UI()
    config = configuration.read()

    if config is None:
        # No configuration mode
        settings = {}
        pname = args.type
    else:
        # Configuration is loaded
        if args.type not in config:
            log.error("No section '%s' in config file." % args.type)
            log.error("Edit configuration using ofxstatement edit-config and "
                      "add section [%s]." % args.type)
            return 1  # error

        settings = dict(config[args.type])

        pname = settings.get('plugin', None)
        if not pname:
            log.error("Specify 'plugin' setting for section [%s]" % args.type)
            return 1  # error

    # pick and configure plugin
    try:
        p = plugin.get_plugin(pname, appui, settings)
    except plugin.PluginNotRegistered:
        log.error("No plugin named '%s' is found" % pname)
        return 1  # error

    # process the input and produce output
    parser = p.get_parser(args.input)
    try:
        statement = parser.parse()
        statement.assert_valid()
    except exceptions.ParseError as e:
        log.error("Parse error on line %s: %s" % (e.lineno, e.message))
        return 2  # error

    with open(args.output, "w") as out:
        writer = ofx.OfxWriter(statement)
        out.write(writer.toxml())

    log.info("Conversion completed: %s" % args.input)
    return 0  # success
コード例 #8
0
ファイル: test_plugin.py プロジェクト: zeldigas/ofxstatement
 def test_get_plugin_not_found(self) -> None:
     with self.assertRaises(plugin.PluginNotRegistered):
         plugin.get_plugin("not_existing", mock.Mock("UI"), mock.Mock("Settings"))
コード例 #9
0
 def test_get_plugin_not_found(self):
     with self.assertRaises(plugin.PluginNotRegistered):
         plugin.get_plugin("not_existing", None, None)
コード例 #10
0
 def test_get_plugin_not_found(self):
     with self.assertRaises(plugin.PluginNotRegistered):
         plugin.get_plugin("not_existing", None, None)