5
$\begingroup$

Bug introduced in V11.2 or earlier and persisting through V11.3

CASE:4072649


Some of notebook types generate notebooks with TaggingRules for their purposes:

Rest @ NotebookGet @ CreateNotebook["SlideShow"]
Notebook[..., TaggingRules -> {"SlideShow" -> True}, ...]

Problem

But "Testing" notebook gets all you have there:

Rest @ NotebookGet @ CreateNotebook["Testing"]

enter image description here

It is not acceptable. The reason is probably that Notebook's TaggingRules inherit too much and not keeping it it mind.

Obvious fix problem

Using workaround from linked topic, one could try to nb = CreateDocument[{}, TaggingRules -> {}] and then convert it CreateNotebook["Testing", nb], but

CreateNotebook::noconv: Converting ... to type Testing is not supported yet.

Question

I have no doubts it is a bug, how to overcome this and create a clean testing notebook programmatically?

$\endgroup$
4
$\begingroup$

The fix is to realize which TaggingRule testing notebook cares about and overwrite all with this one:

nb = CreateNotebook["Testing"];
SetOptions[nb, TaggingRules -> {"$testsRun" -> False}];
Rest @ NotebookGet @ nb

My final goal was to export a testing notebook without prompting a visible notebook. Unfortunately CreateNotebook does not accept options :). So maybe someone will find this code useful:

Export[
    pathToFile
  , Notebook[{}
      (*first two options are not related to the problem but are Git firendly :) *)
    , "TrackCellChangeTimes" -> False
    , PrivateNotebookOptions -> {"FileOutlineCache" -> False}
    , TaggingRules ->  {"$testsRun" -> False}
    , StyleDefinitions -> FrontEnd`FileName[{"MUnit"},"MUnit.nb",CharacterEncoding->"UTF-8"]
    ]
  ]
$\endgroup$
  • 1
    $\begingroup$ CreateNotebook should take options (and for "Template" it's happy to use Visible->False). Unfortunately the "Testing" notebook seems to be all kinds of messed up. $\endgroup$ – b3m2a1 May 30 '18 at 4:14
  • 1
    $\begingroup$ Turns out that's because it just calls MUnit`PaletteNewTestNotebook[] which doesn't take options, but which does set the stylesheet to be FrontEnd`FileName[{"MUnit"}, "MUnit.nb"]. The TaggingRules are actually just inserted by: FrontEndResource["MUnitExpressions", "MUnitStaticToolbar"]. $\endgroup$ – b3m2a1 May 30 '18 at 4:20
  • $\begingroup$ @b3m2a1 thanks, I was sure that the documentation is silent about options but it actually allows them. Another bug to the bucket -.- $\endgroup$ – Kuba May 30 '18 at 6:27
  • $\begingroup$ Yeah it feels these days like a lot of the front-end development is as rushed as what I do... Hopefully that means it's all going into a new stunning 64 bit FE. $\endgroup$ – b3m2a1 May 30 '18 at 8:03

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.