@@ -266,38 +266,38 @@ and copy the following lines into it:
266266
267267.. code-block :: python
268268
269- # Import some of the modules
270- from InitializeSimulation import InitializeSimulation
269+ # Import the required modules
271270 from Utilities import Utilities
272- from Measurements import Measurements
273271 from MonteCarlo import MonteCarlo
274272
275- # Create a function to test if a Child class correctly inherits from a Parent class
276- def test_inheritance ( Child , Parent ):
277- if issubclass (Child, Parent):
278- print (f " { Child. __name__ } correctly inherits from { Parent. __name__ } . " )
279- success = True
280- else :
281- print ( f " { Child. __name__ } does not inherit from { Parent. __name__ } . " )
282- success = False
283- return success
273+ # Make sure that MonteCarlo correctly inherits from Utilities
274+ def test_montecarlo_inherits_from_utilities ( ):
275+ assert issubclass (MonteCarlo, Utilities), " MonteCarlo should inherit from Utilities "
276+ print (" MonteCarlo correctly inherits from Utilities " )
277+
278+ # Make sure that Utilities does not inherit from MonteCarlo
279+ def test_utilities_does_not_inherit_from_montecarlo ():
280+ assert not issubclass (Utilities, MonteCarlo), " Utilities should not inherit from MonteCarlo "
281+ print ( " Utilities does not inherit from MonteCarlo, as expected " )
284282
285- # Make sure that inheritances occur are expected
286- assert test_inheritance(MonteCarlo, Measurements)
287- assert test_inheritance(MonteCarlo, Utilities)
288- assert test_inheritance(MonteCarlo, InitializeSimulation)
289- assert test_inheritance(Utilities, MonteCarlo) is False
283+ test_utilities_does_not_inherit_from_montecarlo()
284+ test_montecarlo_inherits_from_utilities()
290285
291286 .. label :: end_test_1a_class
292287
293- This script should return the four following messages without any *AssertionError *:
288+ When run with Python, this script should return the following messages without
289+ any *AssertionError *:
294290
295291.. code-block :: bw
296292
297- MonteCarlo correctly inherits from Measurements.
298- MonteCarlo correctly inherits from Utilities.
299- MonteCarlo correctly inherits from InitializeSimulation.
300- Utilities does not inherit from MonteCarlo.
293+ Utilities does not inherit from MonteCarlo, as expected
294+ MonteCarlo correctly inherits from Utilities
295+
296+ Alternatively, this test can also be launched using Pytest by typing in a terminal:
297+
298+ .. code-block :: bash
299+
300+ pytest .
301301
302302 We can also test that calling the *__init__ *
303303method of the *MonteCarlo * class does not return any error. In new Python file
@@ -310,21 +310,17 @@ called *test_1b.py*, copy the following lines:
310310 # Import the MonteCarlo class
311311 from MonteCarlo import MonteCarlo
312312
313- # Define a function that try to call the *__init__()* method, return
314- # a variable "success", and print a message.
315- def test_init_method (method ):
313+ # Define a function that try to call the *__init__()* method
314+ def test_init_method ():
316315 try :
317- method .__init__ () # Call the method
316+ MonteCarlo() .__init__ () # Call the method
318317 print (" Method call succeeded" )
319- success = True
320318 except Exception as e:
321319 print (f " Method call raised an error: { e} " )
322- success = False
323- return success
324320
325- # Make sure the function return "True"
326- assert test_init_method(MonteCarlo() )
321+ # Make sure that the method call succeeded
322+ test_init_method()
327323
328324 .. label :: end_test_1b_class
329325
330- Running this second test should return "Method call succeeded".
326+ Running this second test with Python should return "Method call succeeded".
0 commit comments