From cad6537a6bc9fdb495f5f748c3fe802fed48a6d4 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Wed, 22 Jan 2025 08:59:10 +0100 Subject: [PATCH] Add Interactive tests --- .github/workflows/build-and-test.yml | 16 +++--- Plotly.NET.sln | 9 ++++ .../InteractiveTests/Formatting.fs | 51 +++++++++++++++++++ .../InteractiveTests/InteractiveTests.fsproj | 27 ++++++++++ .../InteractiveTests/Main.fs | 6 +++ 5 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 tests/ExtensionLibsTests/InteractiveTests/Formatting.fs create mode 100644 tests/ExtensionLibsTests/InteractiveTests/InteractiveTests.fsproj create mode 100644 tests/ExtensionLibsTests/InteractiveTests/Main.fs diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 71631cc51..d7ccaafad 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -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 @@ -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 diff --git a/Plotly.NET.sln b/Plotly.NET.sln index df437dbcd..ffbb0d4f8 100644 --- a/Plotly.NET.sln +++ b/Plotly.NET.sln @@ -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 @@ -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 @@ -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} diff --git a/tests/ExtensionLibsTests/InteractiveTests/Formatting.fs b/tests/ExtensionLibsTests/InteractiveTests/Formatting.fs new file mode 100644 index 000000000..b2b902fdb --- /dev/null +++ b/tests/ExtensionLibsTests/InteractiveTests/Formatting.fs @@ -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 = + + [] + 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 + + [)>] + 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 = + seq { + yield CustomFormatter() + } + +[] +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" + + ] \ No newline at end of file diff --git a/tests/ExtensionLibsTests/InteractiveTests/InteractiveTests.fsproj b/tests/ExtensionLibsTests/InteractiveTests/InteractiveTests.fsproj new file mode 100644 index 000000000..c843c6fc6 --- /dev/null +++ b/tests/ExtensionLibsTests/InteractiveTests/InteractiveTests.fsproj @@ -0,0 +1,27 @@ + + + + Exe + net8.0 + false + false + + + + + + + + + + + + + + + + + + + + diff --git a/tests/ExtensionLibsTests/InteractiveTests/Main.fs b/tests/ExtensionLibsTests/InteractiveTests/Main.fs new file mode 100644 index 000000000..1f34e91d4 --- /dev/null +++ b/tests/ExtensionLibsTests/InteractiveTests/Main.fs @@ -0,0 +1,6 @@ +module Plotly.NET.Tests +open Expecto + +[] +let main argv = + Tests.runTestsInAssemblyWithCLIArgs [] argv