Skip to content

Commit e4e2d24

Browse files
committed
Improve doctests and FileNotFoundError to ValueError
Based on suggestions by tscrim
1 parent f007410 commit e4e2d24

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/sage/matroids/database_collections.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ def AllMatroids(n, r=None, type="all"):
2929
3030
INPUT:
3131
32-
- ``n`` -- an integer; the number of elements of the matroids
33-
- ``r`` -- an integer (optional, `0 \le r \le n`); the rank of the
34-
matroids. If the type is set to ``unorientable``, then the rank must be
35-
specified.
36-
- ``type`` -- a string (default: ``all``); the type of the matroids.
37-
Either ``all``, ``unorientable``, or any other type for which there
38-
exists an ``is_type()`` attribute.
32+
- ``n`` -- integer; the number of elements of the matroids
33+
- ``r`` -- integer (optional); the rank of the matroids; `0 \le r \le n`
34+
- ``type`` -- string (default: ``'all'``); the type of the matroids; must
35+
be one of the following:
36+
37+
* ``'all'`` -- all matroids; available: (n=0-9), (n=0-12, r=0-2),
38+
(n=0-11, r=3)
39+
* ``'unorientable'`` -- all unorientable matroids; the rank ``r`` must be
40+
specified; available: (n=7-11, r=3), (n=7-9, r=4)
41+
* any other type for which there exists an ``is_type`` method;
42+
availability same as for ``'all'``
3943
4044
OUTPUT: an iterator over matroids
4145
@@ -80,18 +84,17 @@ def AllMatroids(n, r=None, type="all"):
8084
....: M
8185
Traceback (most recent call last):
8286
...
83-
FileNotFoundError: (n=10, r=4, type="all") is not available in the database
87+
ValueError: (n=10, r=4, type="all") is not available in the database
8488
sage: for M in matroids.AllMatroids(12, 3, "unorientable"):
8589
....: M
8690
Traceback (most recent call last):
8791
...
88-
FileNotFoundError: (n=12, r=3, type="unorientable") is not available in the database
92+
ValueError: (n=12, r=3, type="unorientable") is not available in the database
8993
sage: for M in matroids.AllMatroids(8, type="unorientable"):
9094
....: M
9195
Traceback (most recent call last):
9296
...
9397
ValueError: The rank needs to be specified for type "unorientable".
94-
Available: (n=7-11, r=3), (n=7-9, r=4).
9598
sage: for M in matroids.AllMatroids(6, type="nice"):
9699
....: M
97100
Traceback (most recent call last):
@@ -171,10 +174,7 @@ def AllMatroids(n, r=None, type="all"):
171174
)
172175

173176
if r is None and type == "unorientable":
174-
raise ValueError(
175-
"The rank needs to be specified for type \"%s\". " % type +
176-
"Available: (n=7-11, r=3), (n=7-9, r=4)."
177-
)
177+
raise ValueError("The rank needs to be specified for type \"%s\". " % type)
178178

179179
if r is None:
180180
rng = range(0, n+1)
@@ -202,7 +202,7 @@ def AllMatroids(n, r=None, type="all"):
202202
try:
203203
fin = open(file, "r")
204204
except FileNotFoundError:
205-
raise FileNotFoundError(
205+
raise ValueError(
206206
"(n=%s, r=%s, type=\"%s\")" % (n, r, type)
207207
+ " is not available in the database"
208208
)

0 commit comments

Comments
 (0)