示例#1
0
def test_snippet_context_subcontext():
    ctx = CodeSnippetContext()
    ctx.add("foo", "dummy")
    sub = ctx.subcontext("foo")
    sub.add("bar", "dummy")
    ctx.add("baz", "dummy")
    assert "foo" in ctx
    assert "bar" in ctx
    assert ctx.top_level_snippets() == {"foo", "baz"}
    assert ctx.natural_order() == ["baz", "bar", "foo"]
示例#2
0
    def test_object_ts_repr(self):
        ctx = CodeSnippetContext()

        @dataclass()
        class Foo:
            my_field: int
            other_field: str

        tree = Object.match(Foo)
        assert tree.ts_repr(ctx) == "Foo"
        assert ctx.top_level_snippets() == {"Foo"}
        assert ctx.get_snippet("Foo") == """export interface Foo {
示例#3
0
def test_snippet_context_single_snippet():
    ctx = CodeSnippetContext()
    ctx.add("foo", "dummy")
    assert "foo" in ctx
    assert ctx.top_level_snippets() == {"foo"}
    assert ctx.natural_order() == ["foo"]