<strong>Sage</strong> Developer’s <strong>Guide</strong>, Release 6.1.1• If a comment contains not implemented or not tested, it is never tested. It is good to include lines likethis to make clear what we want <strong>Sage</strong> to eventually implement:sage: factor(x*y - x*z)# todo: not implementedIt is also immediately clear to the user that the indicated example does not currently work.• If one of the first 10 lines of a file starts with r""" nodoctest (or """ nodoctest or # nodoctestor % nodoctest or .. nodoctest, or any of these with different spacing), then that file will be skipped.If a directory contains a file nodoctest.py, then that whole directory will be skipped. Neither of this appliesto files or directories which are explicitly given as command line arguments: those are always tested.• If a comment contains optional - PKGNAME, it is not tested unless the --optional=PKGNAMEflag is passed to sage -t. Mark a doctest as optional if it requires optional packages. Runningsage -t --optional=all f.py executes all doctests, including all optional tests. Runningsage -t --optional=sage,sloane_database f.py runs the normal tests (because of--optional=sage), as well as those marked as # optional - sloane_database. For example,the file SAGE_ROOT/src/sage/databases/sloane.py contains the lines:sage: sloane_sequence(60843)# optional - internetand:sage: SloaneEncyclopedia[60843]# optional - sloane_databaseThe first of these just needs internet access, while the second requires that the “sloane_database” package beinstalled. Calling sage -t --optional=all on this file runs both of these tests, while calling sage -t--optional=sage,internet on it will only run the first test. A test requiring several packages shouldbe marked # optional - pkg1 pkg2 and executed by sage -t --optional=sage,pkg1,pkg2f.py.Note: Any words after # optional are interpreted as a list of package names, separated by spaces. Anypunctuation (periods, commas, hyphens, semicolons, ...) after the first word ends the list of packages. Hyphensor colons between the word optional and the first package name are allowed. Therefore, you should notwrite optional: needs package CHomP but simply optional: CHomP. Optional tags are caseinsensitive,so you could also write optional: cHoMp.• If you are documenting a known bug in <strong>Sage</strong>, mark it as known bug or optional:bug. For example:The following should yield 4. See :trac:‘2‘. ::sage: 2+25# optional: bugThen the doctest will be skipped by default, but could be revealed by running sage -t--optional=sage,bug .... (A doctest marked as known bug gets automatically converted tooptional bug).• Some tests (hashing for example) behave differently on 32-bit and 64-bit platforms. You can mark a line (generallythe output) with either # 32-bit or # 64-bit and the testing framework will remove any lines thatdon’t match the current architecture. For example:sage: z = 32sage: z.powermodm_ui(2^32-1, 14)... # 32-bitOverflowError: exp (=4294967295) must be
<strong>Sage</strong> Developer’s <strong>Guide</strong>, Release 6.1.1Using search_src from the <strong>Sage</strong> prompt (or grep), one can easily find the aforementioned keywords. In the caseof todo: not implemented, one can use the results of such a search to direct further development on <strong>Sage</strong>.4.1.6 Running Automated TestsThis section describes <strong>Sage</strong>’s automated testing of test files of the following types: .py, .pyx, .sage, .rst.Briefly, use sage -t to test that the examples in behave exactly as claimed. See the followingsubsections for more details. See also Documentation Strings for a discussion on how to include examples in documentationstrings and what conventions to follow. The chapter Doctesting the <strong>Sage</strong> Library contains a tutorial ondoctesting modules in the <strong>Sage</strong> library.Testing .py, .pyx and .sage FilesRun sage -t to test all code examples in filename.py. Similar remarks apply to .sageand .pyx files:sage -t [--verbose] [--optional] [files and directories ... ]The <strong>Sage</strong> doctesting framework is based on the standard Python doctest module, but with many additional features(such as parallel testing, timeouts, optional tests). The <strong>Sage</strong> doctester recognizes sage: prompts as well as >>>prompts. It also preparses the doctests, just like in interactive <strong>Sage</strong> sessions.Your file passes the tests if the code in it will run when entered at the sage: prompt with no extra imports. Thususers are guaranteed to be able to exactly copy code out of the examples you write for the documentation and havethem work.For more information, see Doctesting the <strong>Sage</strong> Library.Testing ReST DocumentationRun sage -t to test the examples in verbatim environments in ReST documentation.Of course in ReST files, one often inserts explanatory texts between different verbatim environments. To link togetherverbatim environments, use the .. link comment. For example:EXAMPLES::sage: a = 1Next we add 1 to ‘‘a‘‘... link::sage: 1 + a2If you want to link all the verbatim environments together, you can put .. linkall anywhere inthe file, on a line by itself. (For clarity, it might be best to put it near the top of the file.)Then sage -t will act as if there were a .. link before each verbatim environment. The fileSAGE_ROOT/devel/sage/doc/en/tutorial/interfaces.rst contains a .. linkall directive, forexample.You can also put .. skip right before a verbatim environment to have that example skipped when testing the file.This goes in the same place as the .. link in the previous example.4.1. General Conventions 31
- Page 1: Sage Developer’s GuideRelease 6.1
- Page 4 and 5: 7 Indices and tables 129Bibliograph
- Page 6 and 7: Sage Developer’s Guide, Release 6
- Page 8 and 9: Sage Developer’s Guide, Release 6
- Page 10 and 11: Sage Developer’s Guide, Release 6
- Page 12 and 13: Sage Developer’s Guide, Release 6
- Page 14 and 15: Sage Developer’s Guide, Release 6
- Page 16 and 17: Sage Developer’s Guide, Release 6
- Page 18 and 19: Sage Developer’s Guide, Release 6
- Page 20 and 21: Sage Developer’s Guide, Release 6
- Page 22 and 23: Sage Developer’s Guide, Release 6
- Page 24 and 25: Sage Developer’s Guide, Release 6
- Page 26 and 27: Sage Developer’s Guide, Release 6
- Page 28 and 29: Sage Developer’s Guide, Release 6
- Page 30 and 31: Sage Developer’s Guide, Release 6
- Page 32 and 33: Sage Developer’s Guide, Release 6
- Page 36 and 37: Sage Developer’s Guide, Release 6
- Page 38 and 39: Sage Developer’s Guide, Release 6
- Page 40 and 41: Sage Developer’s Guide, Release 6
- Page 42 and 43: Sage Developer’s Guide, Release 6
- Page 44 and 45: Sage Developer’s Guide, Release 6
- Page 46 and 47: Sage Developer’s Guide, Release 6
- Page 48 and 49: Sage Developer’s Guide, Release 6
- Page 50 and 51: Sage Developer’s Guide, Release 6
- Page 52 and 53: Sage Developer’s Guide, Release 6
- Page 54 and 55: Sage Developer’s Guide, Release 6
- Page 56 and 57: Sage Developer’s Guide, Release 6
- Page 58 and 59: Sage Developer’s Guide, Release 6
- Page 60 and 61: Sage Developer’s Guide, Release 6
- Page 62 and 63: Sage Developer’s Guide, Release 6
- Page 64 and 65: Sage Developer’s Guide, Release 6
- Page 66 and 67: Sage Developer’s Guide, Release 6
- Page 68 and 69: Sage Developer’s Guide, Release 6
- Page 70 and 71: Sage Developer’s Guide, Release 6
- Page 72 and 73: Sage Developer’s Guide, Release 6
- Page 74 and 75: Sage Developer’s Guide, Release 6
- Page 76 and 77: Sage Developer’s Guide, Release 6
- Page 78 and 79: Sage Developer’s Guide, Release 6
- Page 80 and 81: Sage Developer’s Guide, Release 6
- Page 82 and 83: Sage Developer’s Guide, Release 6
- Page 84 and 85:
Sage Developer’s Guide, Release 6
- Page 86 and 87:
Sage Developer’s Guide, Release 6
- Page 88 and 89:
Sage Developer’s Guide, Release 6
- Page 90 and 91:
Sage Developer’s Guide, Release 6
- Page 92 and 93:
Sage Developer’s Guide, Release 6
- Page 94 and 95:
Sage Developer’s Guide, Release 6
- Page 96 and 97:
Sage Developer’s Guide, Release 6
- Page 98 and 99:
Sage Developer’s Guide, Release 6
- Page 100 and 101:
Sage Developer’s Guide, Release 6
- Page 102 and 103:
Sage Developer’s Guide, Release 6
- Page 104 and 105:
Sage Developer’s Guide, Release 6
- Page 106 and 107:
Sage Developer’s Guide, Release 6
- Page 108 and 109:
Sage Developer’s Guide, Release 6
- Page 110 and 111:
Sage Developer’s Guide, Release 6
- Page 112 and 113:
Sage Developer’s Guide, Release 6
- Page 114 and 115:
Sage Developer’s Guide, Release 6
- Page 116 and 117:
Sage Developer’s Guide, Release 6
- Page 118 and 119:
Sage Developer’s Guide, Release 6
- Page 120 and 121:
Sage Developer’s Guide, Release 6
- Page 122 and 123:
Sage Developer’s Guide, Release 6
- Page 124 and 125:
Sage Developer’s Guide, Release 6
- Page 126 and 127:
Sage Developer’s Guide, Release 6
- Page 128 and 129:
Sage Developer’s Guide, Release 6
- Page 130 and 131:
Sage Developer’s Guide, Release 6
- Page 132 and 133:
Sage Developer’s Guide, Release 6
- Page 134 and 135:
Sage Developer’s Guide, Release 6
- Page 136 and 137:
Sage Developer’s Guide, Release 6