7
$\begingroup$

I understand that user interaction with GUI can't be tested automatically but some things can be tested using low-level notebook programming functions. Are there any guidelines or limitations of using them in the Mathematica testing framework?

For example, the following code checks if a bug described in InputAliases and SelectionPlaceholder issue in V10 is still present.

SetOptions[
  EvaluationNotebook[],
  InputAliases -> {"[" -> 
     RowBox[{"\[LeftDoubleBracket]", "\[SelectionPlaceholder]", 
       "\[RightDoubleBracket]"}]}
  ];

RawBoxes@"\\[AliasDelimiter]["
oCell = NextCell[];
SelectionMove[oCell , After, CellContents];

NotebookWrite[EvaluationNotebook[], "\\[AliasDelimiter]"]

( NotebookDelete[oCell]; # ) & @ FreeQ[NotebookRead @ oCell , "\[Placeholder]"]

But it fails in Testing Notebook whether expected output matches or not. I understand why, but

  • can I easily integrate such tests into Testing Framework, assuming I will only use Notebook interface to test them? (so no .wlt and testing scripts involved)
$\endgroup$
4
$\begingroup$

I think this question is a mistake from my side but I also think this answer may be useful for future visitors.


testing involves low level notebook programming

It seems I was just expecting from this to be too forgiving, if you make your functions self contained, independent from EvaluationNotebook[], it will work quite fine.

Module[{nb, oCell},
   nb = CreateDocument[{Cell@BoxData@"\\[AliasDelimiter]["}, 
     InputAliases -> {"[" -> RowBox[{
       "\[LeftDoubleBracket]", "\[SelectionPlaceholder]", "\[RightDoubleBracket]"}]}, 
     Visible -> False
   ];

   oCell = First@Cells[nb];

   SelectionMove[oCell, After, CellContents];

   NotebookWrite[nb, "\\[AliasDelimiter]"];

   (NotebookClose[nb]; #) &@FreeQ[NotebookRead@oCell, "\[Placeholder]"]
]

enter image description here


testing requires user interaction

If so, let's ask the user :)

ChoiceDialog[
 Column[{
   "Do you see a blue clipping plane behind the sphere?",
   DocumentNotebook[{ExpressionCell[
      DynamicModule[{vp}, {vp} = 
        Options[Graphics3D, ViewPoint][[All, 2]];
       Graphics3D[{FaceForm[Red, Blue], Sphere[]}, Axes -> True, 
        ViewPoint -> Dynamic[vp], 
        ClipPlanes -> Dynamic@{Append[vp, 1]}, 
        ClipPlanesStyle -> Directive[Opacity[.2], Blue]]], "Notebook",
       "Input"]}, StyleDefinitions -> "Default.nb"]


   }],
 {"Yes" -> True, "No" -> False}
 ]

I've added DocumentNotebook so user can open example with new window where Default.nb options kick in. Dialog prevents rotation of graphics etc, which can be solved but that's shorter solution. enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.