Skip to content

Commit

Permalink
Down to 22 test failures on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom McLaughlin committed Dec 10, 2024
1 parent 8855a92 commit 39958ea
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions tests/src/TestLib/JupyterRunnerContext.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Control.Monad.Reader
import Control.Monad.Trans.Control (MonadBaseControl)
import qualified Data.Aeson as A
import Data.ByteString.Lazy.Char8 as BL8
import Data.Function
import qualified Data.List as L
import Data.Map (Map)
import qualified Data.Map as M
Expand Down Expand Up @@ -92,19 +93,19 @@ type JupyterRunnerMonad m = (
testKernelStdout :: (
HasJupyterRunnerContext context, JupyterRunnerMonad m
) => Text -> Text -> Text -> SpecFree context m ()
testKernelStdout kernel code desired = it [i|#{kernel}: #{code} -> #{desired}|] $
testKernelStdout kernel code desired = it [i|#{kernel} -- #{summarizeCode code} -> #{summarizeCode desired}|] $
testKernelStdout'' kernel code (`shouldBe` Just desired)

testKernelStdout' :: (
HasJupyterRunnerContext context, JupyterRunnerMonad m
) => Text -> Text -> Maybe Text -> SpecFree context m ()
testKernelStdout' kernel code desired = it [i|#{kernel}: #{code} -> #{desired}|] $
testKernelStdout' kernel code desired = it [i|#{kernel} -- #{summarizeCode code} -> #{summarizeCode <$> desired}|] $
testKernelStdout'' kernel code (`shouldBe` desired)

testKernelStdoutCallback :: (
HasJupyterRunnerContext context, JupyterRunnerMonad m
) => Text -> Text -> (Maybe Text -> ExampleT context m ()) -> SpecFree context m ()
testKernelStdoutCallback kernel code cb = it [i|#{kernel}: #{code}|] $
testKernelStdoutCallback kernel code cb = it [i|#{kernel} -- #{summarizeCode code}|] $
testKernelStdout'' kernel code cb

testKernelStdout'' :: (
Expand All @@ -119,13 +120,13 @@ testKernelStdout'' kernel code cb = do
itHasDisplayDatas :: (
HasJupyterRunnerContext context, JupyterRunnerMonad m
) => Text -> Text -> [Map MimeType A.Value] -> SpecFree context m ()
itHasDisplayDatas kernel code desired = it [i|#{kernel}: #{show code} -> #{desired}|] $
itHasDisplayDatas kernel code desired = it [i|#{kernel} -- #{summarizeCode code} -> #{desired}|] $
displayDatasShouldBe kernel code desired

itHasDisplayTexts :: (
HasJupyterRunnerContext context, JupyterRunnerMonad m
) => Text -> Text -> [Maybe A.Value] -> SpecFree context m ()
itHasDisplayTexts kernel code desired = it [i|#{kernel}: #{show code} -> #{desired}|] $
itHasDisplayTexts kernel code desired = it [i|#{kernel} -- #{summarizeCode code} -> #{desired}|] $
displayTextsShouldBe kernel code desired

displayDatasShouldBe :: (
Expand All @@ -150,13 +151,13 @@ displayDatasShouldSatisfy kernel code cb = notebookShouldSatisfy kernel code $ \
itHasExecuteDatas :: (
HasJupyterRunnerContext context, JupyterRunnerMonad m
) => Text -> Text -> [Map MimeType A.Value] -> SpecFree context m ()
itHasExecuteDatas kernel code desired = it [i|#{kernel}: #{show code} -> #{desired}|] $
itHasExecuteDatas kernel code desired = it [i|#{kernel} -- #{summarizeCode code} -> #{desired}|] $
executeDatasShouldBe kernel code desired

itHasExecuteTexts :: (
HasJupyterRunnerContext context, JupyterRunnerMonad m
) => Text -> Text -> [Maybe A.Value] -> SpecFree context m ()
itHasExecuteTexts kernel code desired = it [i|#{kernel}: #{show code} -> #{desired}|] $
itHasExecuteTexts kernel code desired = it [i|#{kernel} -- #{summarizeCode code} -> #{desired}|] $
executeTextsShouldBe kernel code desired

executeDatasShouldBe :: (
Expand All @@ -176,6 +177,24 @@ executeResultsShouldSatisfy kernel code cb = notebookShouldSatisfy kernel code $
let outputs = mconcat [codeOutputs | CodeCell {..} <- notebookCells]
cb ([executeResultData | ExecuteResultOutput {..} <- outputs])

summarizeCode :: Text -> Text
summarizeCode code = code
& truncateCode
& replaceBadCharacters
where
maxLen = 15

truncateCode :: Text -> Text
truncateCode t
| T.length t <= maxLen = t
| otherwise = T.take maxLen t <> "..."

-- Colons will cause an error like this on macOS:
-- error: failed to join paths from `$DYLD_FALLBACK_LIBRARY_PATH` together
-- path segment contains separator `:`
replaceBadCharacters t = t &
T.replace ":" "_"

-- * Core notebook helper

notebookShouldSatisfy :: (
Expand Down

0 comments on commit 39958ea

Please sign in to comment.