forked from TheLartians/TypeScript2Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadme.test.ts
More file actions
56 lines (46 loc) 路 1.16 KB
/
Copy pathreadme.test.ts
File metadata and controls
56 lines (46 loc) 路 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { transpileString } from "./utils";
describe("readme", () => {
it("transpiles the readme example", async () => {
const result = await transpileString(`
export type Foo = {
type: "foo"
foo: number[]
optional?: string
}
/** DocStrings are supported! */
export type Bar = {
type: "bar"
bar: string
/** nested objects need extra declarations in Python */
nested: {
foo: Foo
}
}
export type FooBarMap = {
[key: string]: Foo | Bar
}
export type TupleType = [string, Foo | Bar, any[]]
`);
// note: if this needs to be updated, be sure to update the readme as well
expect(result)
.toEqual(`from typing_extensions import Any, Dict, List, Literal, NotRequired, Tuple, TypedDict, Union
class Foo(TypedDict):
type: Literal["foo"]
foo: List[float]
optional: NotRequired[str]
class Ts2Py_tliGTOBrDv(TypedDict):
foo: Foo
class Bar(TypedDict):
"""
DocStrings are supported!
"""
type: Literal["bar"]
bar: str
nested: Ts2Py_tliGTOBrDv
"""
nested objects need extra declarations in Python
"""
FooBarMap = Dict[str,Union[Foo,Bar]]
TupleType = Tuple[str,Union[Foo,Bar],List[Any]]`);
});
});