Skip to content

Commit

Permalink
Add Interactive tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Jan 22, 2025
1 parent 787cd5b commit cad6537
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 6 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x.x
dotnet-version: |
8.x.x
# 9.x.x
- name: make script executable
run: chmod u+x build.sh
- name: Build and test
Expand All @@ -29,11 +31,13 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x.x
dotnet-version: |
8.x.x
# 9.x.x
- name: Build and test (includes netfx)
working-directory: ./
run: ./build.cmd runtestsall
9 changes: 9 additions & 0 deletions Plotly.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "data", "data", "{0D955C86-2
docs\data\volcano.csv = docs\data\volcano.csv
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "InteractiveTests", "tests\ExtensionLibsTests\InteractiveTests\InteractiveTests.fsproj", "{04BC8CE5-B096-46AD-AB1D-674305BAF59A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -316,6 +318,12 @@ Global
{18F778B2-3409-4309-8C9B-596109072481}.Dotnet|Any CPU.Build.0 = Debug|Any CPU
{18F778B2-3409-4309-8C9B-596109072481}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18F778B2-3409-4309-8C9B-596109072481}.Release|Any CPU.Build.0 = Release|Any CPU
{04BC8CE5-B096-46AD-AB1D-674305BAF59A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04BC8CE5-B096-46AD-AB1D-674305BAF59A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04BC8CE5-B096-46AD-AB1D-674305BAF59A}.Dotnet|Any CPU.ActiveCfg = Debug|Any CPU
{04BC8CE5-B096-46AD-AB1D-674305BAF59A}.Dotnet|Any CPU.Build.0 = Debug|Any CPU
{04BC8CE5-B096-46AD-AB1D-674305BAF59A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04BC8CE5-B096-46AD-AB1D-674305BAF59A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -357,6 +365,7 @@ Global
{7432D5ED-0D0D-4F15-A3AC-CC2BFA4F211F} = {A9025690-FABC-4BD3-AC94-F31B60A948B4}
{2DF92AB2-7B8C-48D5-B779-26BA1F31BCA1} = {A9025690-FABC-4BD3-AC94-F31B60A948B4}
{0D955C86-2E86-4D50-828A-6CF5AD99A119} = {7B09CC0A-F1E1-4094-9DE4-B047581E01F0}
{04BC8CE5-B096-46AD-AB1D-674305BAF59A} = {02886FBB-DB32-4BBB-A93C-E13EBF453ACC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7177F1E1-341C-48AB-9864-6B525FFF7633}
Expand Down
51 changes: 51 additions & 0 deletions tests/ExtensionLibsTests/InteractiveTests/Formatting.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module Tests.Interactive.Formatting

open Expecto

open System
open System.IO

open Microsoft.DotNet.Interactive
open Microsoft.DotNet.Interactive.Formatting

module ConventionBased =

[<AttributeUsage(AttributeTargets.Class)>]
type internal TypeFormatterSourceAttribute(formatterSourceType: Type) =
inherit Attribute()
let mutable preferredMimeTypes : string[] = [||]
member this.TypeFormatterSourceType = formatterSourceType
member this.PreferredMimeTypes
with get() = preferredMimeTypes
and set(v) = preferredMimeTypes <- v

[<TypeFormatterSourceAttribute(typeof<CustomFormatterSource>)>]
type TypeWithCustomFormatter() = class end

and CustomFormatter() =
let mutable mimeType = "text/html"
member this.MimeType
with get() = mimeType
and set(v) = mimeType <- v
member this.Format(instance:obj, writer:TextWriter) =
match instance with
| :? TypeWithCustomFormatter as c ->
writer.Write("Formatting successfull!")
true
| _ -> false

and CustomFormatterSource =
member this.CreateTypeFormatters() : seq<obj> =
seq {
yield CustomFormatter()
}

[<Tests>]
let ``Convention-based Formatting`` =
testList "Convention-based Formatting" [
testCase "Convention based formatter sources can provide lazy registration of custom formatters" <| fun _ ->
let o = ConventionBased.TypeWithCustomFormatter()
let formatted = o.ToDisplayString()
Expect.equal formatted "Formatting successfull!" "Formatting failed"

]
27 changes: 27 additions & 0 deletions tests/ExtensionLibsTests/InteractiveTests/InteractiveTests.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<Compile Include="Formatting.fs" />
<Compile Include="Main.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.Interactive" Version="1.0.0-beta.25070.1" />
<PackageReference Include="Microsoft.DotNet.Interactive.Formatting" Version="1.0.0-beta.25070.1" />
<!--<PackageReference Include="Microsoft.DotNet.Interactive.FSharp" Version="1.0.0-beta.25070.1" />-->
<PackageReference Include="Expecto" Version="10.*" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Plotly.NET.ImageExport\Plotly.NET.ImageExport.fsproj" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions tests/ExtensionLibsTests/InteractiveTests/Main.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Plotly.NET.Tests
open Expecto

[<EntryPoint>]
let main argv =
Tests.runTestsInAssemblyWithCLIArgs [] argv

0 comments on commit cad6537

Please sign in to comment.