On Sat, Jun 2, 2012 at 12:27 PM, Tom Bachmann <[email protected]> wrote: > On 02.06.2012 10:24, Sergiu Ivanov wrote: >> >> I am trying to create custom pretty-printing behaviour for my class >> Morphism. What would be the canonical example for that? I've found >> [0], which says that I could do that by defining a method >> _print_Morphism in one of the pretty printers. However, I have also >> seen what I believe is connected to pretty printing in >> sympy.physics.quantum.gate.Gate for instance, the methods _sympystr(), >> _pretty(), _latex(). Is defining such methods the proper way to go >> today? Also, what would be the difference between defining >> _sympystr() and str()? I can see that Gate does not define str() at >> all. >> > > I know nothing about printing in the quantum module, but in those parts of > sympy I do know, the canonical way to pretty print stuff is to write > _print_Foo methods for the printers (most likely latex and pretty). Just > look at the files sympy/printing/latex.py and > sympy/printing/pretty/pretty.py and search for e.g. _print_Matrix, > _print_meijerg, etc.
Great, thank you! >> And yet another question refers to testing. I can see that there are >> a lot of tests referring to built-in SymPy primitives in >> sympy/printing/pretty/tests/test_pretty.py; also, there are a couple >> pretty-printing related tests in other modules. However, I cannot see >> pretty printing being tested in sympy.physics.quantum. So, is it >> going to be okay if I test the pretty printing of Morphism in the >> tests of category theory module, or should I put the tests in a >> different place? >> > > Apparently, all printing tests should go directly into the printing/ > directory. [Not entirely sure why.] Hm, I see. Sounds like the goal is to keep the tests near the pretty printing methods themselves, which reside in printing/*.py. Sergiu -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
