File tree Expand file tree Collapse file tree 9 files changed +80
-3
lines changed
Expand file tree Collapse file tree 9 files changed +80
-3
lines changed Original file line number Diff line number Diff line change @@ -32,10 +32,12 @@ Target.create "Run" (fun _ ->
3232
3333Target.create " RunTests" ( fun _ ->
3434 run dotnet " build" testsPath
35- [ " native" , dotnet " watch run" testsPath
35+ [ " native" , dotnet " run" testsPath
3636 " python" , dotnet $" run -c Release -p {cliPath} -- --lang Python --exclude Fable.Core --outDir {buildPath}/tests" testsPath
3737 ]
3838 |> runParallel
39+ Shell.Exec( " touch" , $" {buildPath}/tests/__init__.py" ) |> ignore
40+ run pytest $" {buildPath}/tests" " "
3941)
4042
4143Target.create " Format" ( fun _ ->
@@ -54,6 +56,7 @@ let dependencies = [
5456 ==> " Run"
5557
5658 " InstallClient"
59+ ==> " Build"
5760 ==> " RunTests"
5861]
5962
Original file line number Diff line number Diff line change @@ -72,6 +72,10 @@ let createProcess exe arg dir =
7272 |> CreateProcess.ensureExitCode
7373
7474let dotnet = createProcess " dotnet"
75+
76+
77+ let pytest = createProcess " pytest"
78+
7579let npm =
7680 let npmPath =
7781 match ProcessUtils.tryFindFileOnPath " npm" with
Original file line number Diff line number Diff line change 1+ module Fable.Python.Builtins
2+
3+ open System.Collections .Generic
4+ open Fable.Core
5+
6+ // fsharplint:disable MemberNames,InterfaceNames
7+
8+ type Builtins =
9+ abstract print : obj : obj -> unit
10+ abstract map : ( 'T1 -> 'T2 ) * IEnumerable < 'T1 > -> IEnumerable < 'T2 >
11+ abstract map : ( 'T1 * 'T2 -> 'T3 ) * IEnumerable < 'T1 > * IEnumerable < 'T2 > -> IEnumerable < 'T3 >
12+ abstract map : ( 'T1 * 'T2 * 'T3 -> 'T4 ) * IEnumerable < 'T1 > * IEnumerable < 'T2 > * IEnumerable < 'T3 > -> IEnumerable < 'T4 >
13+
14+ let builtins : Builtins = nativeOnly
Original file line number Diff line number Diff line change 66 <WarnOn >3390;$(WarnOn)</WarnOn >
77 </PropertyGroup >
88 <ItemGroup >
9+ <Compile Include =" Builtins.fs" />
910 <Compile Include =" Json.fs" />
1011 </ItemGroup >
1112 <ItemGroup >
1213 <ProjectReference Include =" ../../Fable/src/Fable.Core/Fable.Core.fsproj" />
1314 </ItemGroup >
15+ <ItemGroup >
16+ <Content Include =" pyproject.toml; *.fsproj; **\*.fs; **\*.fsi" PackagePath =" fable\" />
17+ </ItemGroup >
1418 <Import Project =" ..\.paket\Paket.Restore.targets" />
1519</Project >
Original file line number Diff line number Diff line change 22
33open Fable.Core
44
5+ // fsharplint:disable MemberNames,InterfaceNames
56
67type Json =
78 abstract dumps : obj : obj -> string
9+ abstract loads : string -> obj
810
9- [<ImportDefault( " os " ) >]
11+ [<ImportDefault( " json " ) >]
1012let json : Json = nativeOnly
Original file line number Diff line number Diff line change 1+
2+ [tool .poetry ]
3+ name = " fable-python"
4+ version = " 0.1.0"
5+ description = " Python bindings for Fable"
6+ authors = [
" Dag Brattli <[email protected] >" ]
7+ license = " MIT"
8+
9+ [tool .poetry .dependencies ]
10+ python = " ^3.8"
11+ fable-library = " ^0.0.1"
12+
13+ [tool .poetry .dev-dependencies ]
14+
15+ [build-system ]
16+ requires = [" poetry-core>=1.0.0" ]
17+ build-backend = " poetry.core.masonry.api"
Original file line number Diff line number Diff line change 1313 </ItemGroup >
1414 <ItemGroup >
1515 <Compile Include =" Util.fs" />
16+ <Compile Include =" TestBuiltins.fs" />
1617 <Compile Include =" TestJson.fs" />
1718 <Compile Include =" Main.fs" />
1819 </ItemGroup >
Original file line number Diff line number Diff line change 1+ module Fable.Python.Tests.Builtins
2+
3+ open Util.Testing
4+ open Fable.Python .Builtins
5+
6+ // type MyObject = {
7+ // Foo: int
8+ // Bar: string
9+ // }
10+
11+ [<Fact>]
12+ let ``test print works`` () =
13+ let result = builtins.print " Hello, world!"
14+ result |> equal ()
Original file line number Diff line number Diff line change 11module Fable.Python.Tests.Json
22
33open Util.Testing
4+ open Fable.Python .Json
45
6+ // type MyObject = {
7+ // Foo: int
8+ // Bar: string
9+ // }
510
611[<Fact>]
7- let ``test Seq.empty works`` () =
12+ let ``test works`` () =
813 let result = true
914 result |> equal true
15+
16+ [<Fact>]
17+ let ``test json dumps works`` () =
18+ let object = {| A= 10 ; B= 20 |}
19+ let result = json.dumps object
20+ result |> equal """ {"A": 10, "B": 20}"""
21+
22+ [<Fact>]
23+ let ``test json loads works`` () =
24+ let input = """ {"Foo": 10, "Bar": "test"}"""
25+ let object = {| Foo= 10 ; Bar= " test" |}
26+ let result : {| Foo: int ; Bar: string |}= unbox ( json.loads input)
27+ result |> equal object
You can’t perform that action at this time.
0 commit comments