Ejemplo n.º 1
0
    def test(c):
        m = Mocker()
        sf = SyntaxFactory()
        log = m.replace("editxt.syntax.log", passthrough=False)
        glob = m.replace("glob.glob", passthrough=False)
        exists = m.replace("os.path.exists", passthrough=False)
        load = sf.load_definition = m.mock()
        if c.path and exists(c.path) >> c.exists:
            info = {
                "disabled": dict(name="dis", disabled=True, filepatterns=[]), # should cause info log

                # these should cause error log
                "incomplete1": {},
                "incomplete2": dict(name="none"),
                "incomplete3": dict(filepatterns=[]),

                # should only register twice despite duplication
                "python": dict(name="python", filepatterns=["*.py", "*.py", "*.pyw"]),

                "sql": dict(name="sequel", filepatterns=["*.sql"]),
                "text": dict(name="text", filepatterns=["*.txt"]),
                "text2": dict(name="text", filepatterns=["*.txt", "*.text"]),
                "text3": dict(name="text", disabled=True, filepatterns=["*.txt", "*.text"]),
            }
            glob(os.path.join(c.path, "*" + const.SYNTAX_DEF_EXTENSION)) >> sorted(info)
            def do(name):
                data = dict(info[name])
                if name.startswith("incomplete"):
                    raise Exception("incomplete definition: %r" % (data,))
                data.setdefault("disabled", False)
                if "filepatterns" in data:
                    data["filepatterns"] = set(data["filepatterns"])
                return type("sdef", (object,), data)()
            expect(load(ANY)).count(len(info)).call(do)
            for fname, data in sorted(info.iteritems()):
                if fname.startswith("incomplete"):
                    log.error(ANY, fname, exc_info=True)
                else:
                    pats = ", ".join(sorted(set(data.get("filepatterns", []))))
                    stat = [data["name"], "[%s]" % pats]
                    if fname in ("text", "text2", "text4"):
                        stat.extend(["overrides", "*.txt"])
                    elif fname in ("disabled", "text3"):
                        stat.append("DISABLED")
                    stat.append(fname)
                    log.info(ANY, " ".join(stat))
            patterns = set(["*.py", "*.pyw", "*.sql", "*.text", "*.txt"])
        else:
            patterns = set(["*.txt"])
        with m:
            sf.load_definitions(c.path)
            eq_(set(sf.registry), patterns)
Ejemplo n.º 2
0
    def test(c):
        m = Mocker()
        sf = SyntaxFactory()
        log = m.replace("editxt.syntax.log")
        glob = m.replace("glob.glob")
        exists = m.replace("os.path.exists")
        load = sf.load_definition = m.mock()
        if c.path and exists(c.path) >> c.exists:
            info = {
                "disabled": dict(name="dis", disabled=True, filepatterns=[]), # should cause info log

                # these should cause error log
                "incomplete1": {},
                "incomplete2": dict(name="none"),
                "incomplete3": dict(filepatterns=[]),

                # should only register twice despite duplication
                "python": dict(name="python", filepatterns=["*.py", "*.py", "*.pyw"]),

                "sql": dict(name="sequel", filepatterns=["*.sql"]),
                "text": dict(name="text", filepatterns=["*.txt"]),
                "text2": dict(name="text", filepatterns=["*.txt", "*.text"]),
                "text3": dict(name="text", disabled=True, filepatterns=["*.txt", "*.text"]),
            }
            glob(os.path.join(c.path, "*" + const.SYNTAX_DEF_EXTENSION)) >> sorted(info)
            def do(name):
                data = dict(info[name])
                if name.startswith("incomplete"):
                    raise Exception("incomplete definition: %r" % (data,))
                data.setdefault("disabled", False)
                if "filepatterns" in data:
                    data["filepatterns"] = set(data["filepatterns"])
                return type("sdef", (object,), data)()
            expect(load(ANY)).count(len(info)).call(do)
            for fname, data in sorted(info.items()):
                if fname.startswith("incomplete"):
                    log.error(ANY, fname, exc_info=True)
                else:
                    pats = ", ".join(sorted(set(data.get("filepatterns", []))))
                    stat = [data["name"], "[%s]" % pats]
                    if fname in ("text", "text2", "text4"):
                        stat.extend(["overrides", "*.txt"])
                    elif fname in ("disabled", "text3"):
                        stat.append("DISABLED")
                    stat.append(fname)
                    log.info(ANY, " ".join(stat))
            patterns = set(["*.py", "*.pyw", "*.sql", "*.text", "*.txt"])
        else:
            patterns = set(["*.txt"])
        with m:
            sf.load_definitions(c.path)
            eq_(set(sf.registry), patterns)
Ejemplo n.º 3
0
def test_init_syntax_definitions():
    import editxt.syntax as syntax
    m = Mocker()
    app = Application(profile='/editxtdev')
    rsrc_path = m.method(app.resource_path)() >> "/tmp/resources"
    SyntaxFactory = m.replace(syntax, 'SyntaxFactory', spec=False)
    sf = SyntaxFactory() >> m.mock(syntax.SyntaxFactory)
    app_log = m.replace("editxt.application.log")
    for path, info in [(rsrc_path, False), ('/editxtdev', True)]:
        sf.load_definitions(os.path.join(path, const.SYNTAX_DEFS_DIR), info)
    sf.index_definitions()
    with m:
        app.init_syntax_definitions()
Ejemplo n.º 4
0
def test_init_syntax_definitions():
    import editxt.syntax as syntax
    m = Mocker()
    app = Application(profile='/editxtdev')
    rsrc_path = m.method(app.resource_path)() >> "/tmp/resources"
    SyntaxFactory = m.replace(syntax, 'SyntaxFactory', spec=False)
    sf = SyntaxFactory() >> m.mock(syntax.SyntaxFactory)
    app_log = m.replace("editxt.application.log")
    for path, info in [(rsrc_path, False), ('/editxtdev', True)]:
        sf.load_definitions(join(path, const.SYNTAX_DEFS_DIR), info)
    sf.index_definitions()
    with m:
        app.init_syntax_definitions()
Ejemplo n.º 5
0
def get_syntax_definition(name, cache={}):
    if isinstance(name, NoHighlight):
        return name
    try:
        return cache[name].get(name)
    except KeyError:
        pass
    from os.path import abspath, dirname, join

    root = dirname(dirname(dirname(abspath(__file__))))
    loader = SyntaxFactory()
    loader.load_definitions(join(root, "resources/syntax"), False)
    cache[name] = loader
    return loader.get(name)