Skip to content

Commit

Permalink
Setup proof of concept 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Sep 13, 2023
1 parent 0cd060b commit e075296
Show file tree
Hide file tree
Showing 25 changed files with 4,716 additions and 329 deletions.
14 changes: 7 additions & 7 deletions Fable.Pytest.sln → Fable.Pyxpecto.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fable.Pytest", "src\Fable.Pytest.fsproj", "{83B388B0-10A0-4DF9-B9F2-009172B6E4D8}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fable.Pyxpecto", "src\Fable.Pyxpecto.fsproj", "{83B388B0-10A0-4DF9-B9F2-009172B6E4D8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0058D3AF-CB78-455B-9699-74C2C571255D}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
build.cmd = build.cmd
Pipfile = Pipfile
package.json = package.json
README.md = README.md
EndProjectSection
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Build", "build\Build.fsproj", "{F7027BE5-755C-4857-9AD5-2B58953A7FFE}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fable.Pytest.Tests", "tests\Fable.Pytest.Tests\Fable.Pytest.Tests.fsproj", "{6BF3B171-2ECD-46A7-A00F-5B2FBBCA8F30}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fable.Pyxpecto.Tests", "tests\Fable.Pyxpecto.Tests.fsproj", "{78D65800-18D8-489F-99F9-9157D52F3749}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -31,10 +31,10 @@ Global
{F7027BE5-755C-4857-9AD5-2B58953A7FFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7027BE5-755C-4857-9AD5-2B58953A7FFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7027BE5-755C-4857-9AD5-2B58953A7FFE}.Release|Any CPU.Build.0 = Release|Any CPU
{6BF3B171-2ECD-46A7-A00F-5B2FBBCA8F30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BF3B171-2ECD-46A7-A00F-5B2FBBCA8F30}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BF3B171-2ECD-46A7-A00F-5B2FBBCA8F30}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BF3B171-2ECD-46A7-A00F-5B2FBBCA8F30}.Release|Any CPU.Build.0 = Release|Any CPU
{78D65800-18D8-489F-99F9-9157D52F3749}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78D65800-18D8-489F-99F9-9157D52F3749}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78D65800-18D8-489F-99F9-9157D52F3749}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78D65800-18D8-489F-99F9-9157D52F3749}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 0 additions & 12 deletions Pipfile

This file was deleted.

77 changes: 0 additions & 77 deletions Pipfile.lock

This file was deleted.

78 changes: 66 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,72 @@
# Fable.Pytest
# Fable.Pyxpecto

## Ressources
> This repository is heavily inspired by [Fable.Mocha](https://github.com/Zaid-Ajaj/Fable.Mocha/) by the awesome @Zaid-Ajaj.
- [Pytest-Docs](https://docs.pytest.org/en/stable/how-to/capture-warnings.html)
- [Fable.Mocha](https://github.com/Zaid-Ajaj/Fable.Mocha/blob/master/src/Mocha.fs)
- [Fable Features](https://fable.io/Fable.Python/communicate/py-from-fable.html)
- [Fable.Core.Testing](https://github.com/fable-compiler/Fable/blob/main/src/Fable.Core/Fable.Core.Util.fs)
Fable python library for testing. Inspired by the popular Expecto library for F# and adopts the testList, testCase and testCaseAsync primitives for defining tests.

## Running tests

Use the following syntax to automatically switch between Expecto, Fable.Mocha and Pyxpecto:

```fsharp
#if FABLE_COMPILER_PYTHON
open Fable.Pyxpecto
#endif
#if FABLE_COMPILER_JAVASCRIPT
open Fable.Mocha
#endif
#if !FABLE_COMPILER
open Expecto
#endif
```

```fsharp
[<EntryPoint>]
let main argv =
#if FABLE_COMPILER_PYTHON
Pyxpecto.runTests all
#endif
#if FABLE_COMPILER_JAVASCRIPT
Mocha.runTests all
#endif
#if !FABLE_COMPILER
Tests.runTestsWithCLIArgs [] [||] all
#endif
```

> 👀 Everything in curly braces are placeholders
1. Transpile test project to python `dotnet fable {path/to/tests} --lang py -o {path/to/tests}/py`
2. Run tests `py {path/to/tests}/{EntryFileName.py}`

## Development

### How was this set up
### Requirements

- Python
- check with `py --version` (Tested with `Python 3.11.1`)
- [Dotnet SDK](https://dotnet.microsoft.com/en-us/download)
- check with `dotnet --version` (Tested with `7.0.306`)
- Node
- check with `node --version` (Tested with `v18.16.1`)
- npm
- check with `node --version` (Tested with `9.2.0`)

### Setup

Run all commands in root.

1. `dotnet tool restore`
1. `npm install`

### Routines

#### Tests

`./build.cmd runtests`

Can be specified to run tests for specific environment.

1. Check `pip` installed with `pip --version` (Tested with pip 22.0.4 and python 3.9)
2. Install `pipenv` with `py -m pip install pipenv`
3. Test with `py -m pipenv --version`
2. Install pytest globally with `py -m pipenv install pytest`. Created Pipfile
3. Run tests with `py -m pipenv run pytest`
- `./build.cmd runtestsdotnet`
- `./build.cmd runtestsjs`
- `./build.cmd runtestspy` (Currently failing, but commands can be run after another to make it work)
5 changes: 3 additions & 2 deletions build/Build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ open BasicTasks
open TestTasks
open PackageTasks
open ReleaseTasks
open FableTasks

let _ = FableTasks.fable
let _ = TestTasks.runTestsPy
let _ = TestTasks.runTestsDotNet
let _ = TestTasks.runTestsJs

/// Full release of nuget package, git tag, and documentation for the stable version.
let _release =
Expand Down
1 change: 0 additions & 1 deletion build/Build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<Compile Include="ProjectInfo.fs" />
<Compile Include="ReleaseNotesTasks.fs" />
<Compile Include="BasicTasks.fs" />
<Compile Include="FableTasks.fs" />
<Compile Include="TestTasks.fs" />
<Compile Include="PackageTasks.fs" />
<Compile Include="ReleaseTasks.fs" />
Expand Down
21 changes: 0 additions & 21 deletions build/FableTasks.fs

This file was deleted.

4 changes: 0 additions & 4 deletions build/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ let py =

createProcess path

let pipenv cmd execPath =
let cmd = "-m pipenv " + cmd
py cmd execPath

let run proc arg dir =
proc arg dir
|> Proc.run
Expand Down
9 changes: 2 additions & 7 deletions build/ProjectInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

open Fake.Core

let project = "Fable.Pytest"
let project = "Fable.Pyxpecto"

let testProjects =
[
// add relative paths (from project root) to your testprojects here
"tests/Fable.Pytest.Tests"
]

let pyTestProjects =
[
"tests/NativeTests"
"tests"
]

let solutionFile = $"{project}.sln"
Expand Down
13 changes: 10 additions & 3 deletions build/TestTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ let runTestsDotNet = BuildTask.create "RunTestsDotnet" [clean; build;] {
open Helpers

let runTestsPy = BuildTask.create "RunTestsPy" [clean; build;] {
for test in ProjectInfo.pyTestProjects do
run pipenv $"run pytest {test}/Main.py" ""
for test in ProjectInfo.testProjects do
run dotnet $"fable {test} --lang py -o {test}/py" ""
run py $"{test}/py/main.py" ""
}

let runTests = BuildTask.create "RunTests" [clean; build; runTestsDotNet; runTestsPy] {
let runTestsJs = BuildTask.create "RunTestsJs" [clean; build;] {
for test in ProjectInfo.testProjects do
run dotnet $"fable {test} -o {test}/js" ""
run npm $"test" ""
}

let runTests = BuildTask.create "RunTests" [clean; build; runTestsDotNet; runTestsPy; runTestsJs] {
()
}
Loading

0 comments on commit e075296

Please sign in to comment.