Skip to content

Commit 09b7e30

Browse files
committed
Now has script to run doctests
1 parent c01ef80 commit 09b7e30

File tree

8 files changed

+80
-44
lines changed

8 files changed

+80
-44
lines changed

ciw/tests/doctests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import doctest
2+
import os
3+
import unittest
4+
5+
6+
def load_tests(loader, tests, ignore):
7+
for root, dirs, files in os.walk("./docs"):
8+
for f in files:
9+
if f.endswith(".rst"):
10+
tests.addTests(doctest.DocFileSuite(os.path.join(root, f)))
11+
12+
return tests
13+
14+
15+
if __name__ == '__main__':
16+
unittest.main()

docs/Basics/further_shell.rst

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,48 @@ First, set up a parameters file as described in :ref:`parameters-file`.
77
Now importing Ciw and the parameters file as a dictionary is simple::
88

99
>>> import ciw
10-
>>> params = ciw.load_parameters(<path_to_file>)
11-
>>> params["Number_of_servers"]
12-
[2, 1, 1]
10+
>>> params = ciw.load_parameters(<path_to_file>) # doctest:+SKIP
11+
>>> params["Number_of_servers"] # doctest:+SKIP
12+
[2, 1, 1] # doctest:+SKIP
1313

1414
Set up a Simulation object, from which all parameters can also be accessed::
1515

16-
>>> Q = ciw.Simulation(params)
17-
>>> Q.number_of_nodes
18-
3
19-
>>> Q.queue_capacities
20-
['Inf', 'Inf', 10]
21-
>>> Q.lmbda # The arrival rates of the system
22-
[[1.0, 1.8, 7.25], [6.0, 4.5, 2.0]]
23-
>>> Q.lmbda[0] # Arrival rates of the 0th class
24-
[1.0, 1.8, 7.2]
16+
>>> Q = ciw.Simulation(params) # doctest:+SKIP
17+
>>> Q.number_of_nodes # doctest:+SKIP
18+
3 # doctest:+SKIP
19+
>>> Q.queue_capacities # doctest:+SKIP
20+
['Inf', 'Inf', 10] # doctest:+SKIP
21+
>>> Q.lmbda # The arrival rates of the system # doctest:+SKIP
22+
[[1.0, 1.8, 7.25], [6.0, 4.5, 2.0]] # doctest:+SKIP
23+
>>> Q.lmbda[0] # Arrival rates of the 0th class # doctest:+SKIP
24+
[1.0, 1.8, 7.2] # doctest:+SKIP
2525

2626
A full list of Ciw's objects and attributes can be found here: :ref:`objects-attributes`
2727
Now to run a simulation simply run the following method::
2828

29-
>>> Q.simulate_until_max_time()
29+
>>> Q.simulate_until_max_time() # doctest:+SKIP
3030

3131
Individuals' data records can be accessed directly using the following methods::
3232

33-
>>> all_individuals = Q.get_all_individuals() # Creates a list of all individuals in the system
34-
>>> all_individuals[0]
35-
Individual 13
36-
>>> all_individuals[0].data_records.values()[0][0].wait # Time Individual 13 was waiting for this instance of service
37-
0.39586652218275364
38-
>>> all_individuals[0].data_records.values()[0][0].arrival_date # Time Individual 13 arrived for this instance of service
39-
0.5736475797750542
33+
>>> all_individuals = Q.get_all_individuals() # Creates a list of all individuals in the system # doctest:+SKIP
34+
>>> all_individuals[0] # doctest:+SKIP
35+
Individual 13 # doctest:+SKIP
36+
>>> all_individuals[0].data_records.values()[0][0].wait # Time Individual 13 was waiting for this instance of service # doctest:+SKIP
37+
0.39586652218275364 # doctest:+SKIP
38+
>>> all_individuals[0].data_records.values()[0][0].arrival_date # Time Individual 13 arrived for this instance of service # doctest:+SKIP
39+
0.5736475797750542 # doctest:+SKIP
4040

4141
A full list of data records can be obtained, with or without headers::
4242
43-
>>> records = Q.get_all_records(headers=True)
44-
>>> records[:3]
45-
[['I.D. Number', 'Customer Class', 'Node', 'Arrival Date', 'Waiting Time', 'Service Start Date', 'Service Time', 'Service End Date', 'Time Blocked', 'Exit Date'],
46-
[1, 0, 1, 0.16207509531905792, 0.0, 0.16207509531905792, 0.014861757967438763, 0.1769368532864967, 0.0, 0.1769368532864967],
47-
[2, 0, 1, 0.4628182409609607, 0.0, 0.4628182409609607, 0.13420139243827206, 0.5970196333992328, 0.0, 0.5970196333992328]]
43+
>>> records = Q.get_all_records(headers=True) # doctest:+SKIP
44+
>>> records[:3] # doctest:+SKIP
45+
[['I.D. Number', 'Customer Class', 'Node', 'Arrival Date', 'Waiting Time', 'Service Start Date', 'Service Time', 'Service End Date', 'Time Blocked', 'Exit Date'], # doctest:+SKIP
46+
[1, 0, 1, 0.16207509531905792, 0.0, 0.16207509531905792, 0.014861757967438763, 0.1769368532864967, 0.0, 0.1769368532864967], # doctest:+SKIP
47+
[2, 0, 1, 0.4628182409609607, 0.0, 0.4628182409609607, 0.13420139243827206, 0.5970196333992328, 0.0, 0.5970196333992328]] # doctest:+SKIP
4848

4949

5050
The full list data records can be written to a csv file::
5151

52-
>>> Q.write_records_to_file(<path_to_file>)
52+
>>> Q.write_records_to_file(<path_to_file>) # doctest:+SKIP
5353

5454
Please see :ref:`output-file` for an explanation of the data contained here.

docs/Basics/getting_started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ Ciw can then use this parameters dictionary to run the simulation::
4949

5050
Once this simulation has been run, :ref:`output-file` can be written to file through::
5151

52-
>>> Q.write_records_to_file(<path_to_file>)
52+
>>> Q.write_records_to_file(<path_to_file>) # doctest:+SKIP

docs/Basics/output_file.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The Output Data
66

77
Once a simulation has been run, the following method may be called to write a data file::
88

9-
>>> Q.write_records_to_file('data/file/location.csv')
9+
>>> Q.write_records_to_file(<path_to_file>) # doctest:+SKIP
1010

1111
This file contains does not contain summary statistics, but all the information that happened during the simulation in raw format.
1212
Each time an individual completes service at a service station, a data record of that service is kept.
@@ -28,4 +28,4 @@ The following table summarises the columns:
2828

2929
The :code:`write_records_to_file` method writes a header as default. To disable this feature, input :code:`headers=False`::
3030

31-
>>> Q.write_records_to_file(<path_to_file>, header=False)
31+
>>> Q.write_records_to_file(<path_to_file>, header=False) # doctest:+SKIP

docs/Basics/parameters_dict.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ And then each customer class requires:
2626

2727
A full example of the parameters dictionary for a three node network with two classes of customer is shown below::
2828

29-
>>> {'Arrival_rates': {'Class 1': [1.0, 1.8, 7.25],
30-
'Class 0': [6.0, 4.5, 2.0]},
31-
... 'Number_of_nodes': 3,
32-
... 'detect_deadlock': False,
33-
... 'Simulation_time': 2500,
34-
... 'Number_of_servers': [2, 1, 1],
35-
... 'Queue_capacities': ['Inf', 'Inf', 10],
36-
... 'Number_of_classes': 2,
37-
... 'Service_distributions': {'Class 1': [['Exponential', 8.5], ['Triangular', 0.1, 0.8, 0.95], ['Exponential', 3.0]],
38-
... 'Class 0': [['Exponential', 7.0], ['Exponential', 5.0], ['Gamma', 0.4, 0.6]]},
29+
>>> params = {'Arrival_rates': {'Class 1': [1.0, 1.8, 7.25],
30+
... 'Class 0': [6.0, 4.5, 2.0]},
31+
... 'Number_of_nodes': 3,
32+
... 'detect_deadlock': False,
33+
... 'Simulation_time': 2500,
34+
... 'Number_of_servers': [2, 1, 1],
35+
... 'Queue_capacities': ['Inf', 'Inf', 10],
36+
... 'Number_of_classes': 2,
37+
... 'Service_distributions': {'Class 1': [['Exponential', 8.5], ['Triangular', 0.1, 0.8, 0.95], ['Exponential', 3.0]],
38+
... 'Class 0': [['Exponential', 7.0], ['Exponential', 5.0], ['Gamma', 0.4, 0.6]]},
3939
... 'Transition_matrices': {'Class 1': [[0.7, 0.05, 0.05], [0.5, 0.1, 0.4], [0.2, 0.2, 0.2]],
4040
... 'Class 0': [[0.1, 0.6, 0.2], [0.0, 0.5, 0.5], [0.3, 0.1, 0.1]]}}
4141

docs/Examples/mm1.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ Standard queueing theory gives the expected wait in an M/M/1 queue as :math:`\ma
1212
We set up the parameters in ASQ::
1313

1414
>>> params_dict = {'Arrival_rates': {'Class 0': [3.0]},
15-
... 'Service_distributions':{'Class 0': [['Exponential', 5.0]]},
15+
... 'Service_distributions': {'Class 0': [['Exponential', 5.0]]},
1616
... 'Simulation_time': 250,
17-
... 'Transition_matrices': {'Class 0': [[0.0]]}
17+
... 'Transition_matrices': {'Class 0': [[0.0]]},
18+
... 'Number_of_servers': [1]
1819
... }
1920

2021
The following code repeats the experiment 100 times, only recording waits for those that arrived after a warm-up time of 50.
2122
It then returns the average wait in the system::
22-
23+
24+
>>> import ciw
25+
>>> from random import seed
2326
>>> def iteration(warmup):
2427
... Q = ciw.Simulation(params_dict)
2528
... Q.simulate_until_max_time()

docs/Features/deadlock.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ In order to take advantage of this feature, set deadlock detection option to Tru
1313
Then use the :code:`simulate_until_deadlock` method to return the times to deadlock from each state::
1414

1515
>>> import ciw
16-
>>> Q = ciw.Simulation(deadlock_params)
17-
>>> times = Q.simulate_until_deadlock()
16+
>>> Q = ciw.Simulation(deadlock_params) # doctest:+SKIP
17+
>>> times = Q.simulate_until_deadlock() # doctest:+SKIP
1818

1919
where :code:`times` is a dictionary with states as keys and times to deadlock as values. Note that :code:`Simulation_time` is ingnored in this case.
2020

@@ -41,6 +41,7 @@ Parameters::
4141
Running until deadlock::
4242

4343
>>> import ciw
44+
>>> from random import seed
4445
>>> seed(99)
4546
>>> Q = ciw.Simulation(params)
4647
>>> times = Q.simulate_until_deadlock()

doctests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import doctest
2+
import os
3+
import unittest
4+
5+
6+
def load_tests(loader, tests, ignore):
7+
for root, dirs, files in os.walk("./docs"):
8+
for f in files:
9+
if f.endswith(".rst"):
10+
tests.addTests(doctest.DocFileSuite(os.path.join(root, f)))
11+
12+
return tests
13+
14+
15+
if __name__ == '__main__':
16+
unittest.main()

0 commit comments

Comments
 (0)