From 3c8377a35bf073056640e6643d12bf95acb39eb7 Mon Sep 17 00:00:00 2001
From: Owen Arnold <owen.arnold@stfc.ac.uk>
Date: Mon, 28 Jan 2019 15:32:54 +0000
Subject: [PATCH] refs #24597. Convert to doctest

---
 docs/source/concepts/ComponentInfo.rst | 29 +++++++++++--------
 docs/source/concepts/DetectorInfo.rst  | 40 ++++++++++++--------------
 2 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/docs/source/concepts/ComponentInfo.rst b/docs/source/concepts/ComponentInfo.rst
index 5aa5257c45e..32a3b7fe406 100644
--- a/docs/source/concepts/ComponentInfo.rst
+++ b/docs/source/concepts/ComponentInfo.rst
@@ -20,15 +20,20 @@ Examples of using ``ComponentInfo`` in python
 
 Print indices of detectors in "bank1" that are masked
 
-.. code-block:: python 
-
-  from mantid.simpleapi import CreateSampleWorkspace
-
-  ws = CreateSampleWorkspace()
-  comp_info = ws.componentInfo()
-  det_info = ws.detectorInfo()
-  bank_index compinfo.indexOfAny('bank1')
-  for det_index in compinfo.detectorsInSubtree(bank_index):
-      if det_info.isMasked(int(det_index)):
-          print('Masked detector of bank1, ', det_index)
-
+.. testcode:: show_masked_detectors_in_bank 
+
+   from mantid.simpleapi import CreateSampleWorkspace
+   
+   ws = CreateSampleWorkspace()
+   comp_info = ws.componentInfo()
+   det_info = ws.detectorInfo()
+   det_info.setMasked(2, True) # Mask  a bank 1 detector for demo
+   det_info.setMasked(len(det_info)-1, True) # Mask detector not in bank 1
+   bank_index = comp_info.indexOfAny('bank1')
+   for det_index in comp_info.detectorsInSubtree(bank_index):
+       if det_info.isMasked(int(det_index)):
+           print('Masked detector index of bank1 is {}'.format(det_index))
+
+.. testoutput:: show_masked_detectors_in_bank
+
+   Masked detector index of bank1 is 2
diff --git a/docs/source/concepts/DetectorInfo.rst b/docs/source/concepts/DetectorInfo.rst
index a7e6783b04c..288e2ca301d 100644
--- a/docs/source/concepts/DetectorInfo.rst
+++ b/docs/source/concepts/DetectorInfo.rst
@@ -16,30 +16,26 @@ Introduction
 Python Interface
 ----------------
 
-Examples of using ``DetectorInfo`` in python
+Example of using ``DetectorInfo`` in python
 
-Mask detectors at some distance from the source
+**Mask detectors at some distance from the source**
 
-.. code-block:: python 
 
-  from mantid.simpleapi import CreateSampleWorkspace
+.. testcode:: mask_detectors 
 
-  # Test workspace with instrument
-  ws = CreateSampleWorkspace()
-  det_info = ws.detectorInfo();
-  for item in det_info:
-      if not item.isMonitor and item.l2 > 2.0:
-          item.setMasked(True)
+   from mantid.simpleapi import CreateSampleWorkspace
+   
+   # Test workspace with instrument
+   ws = CreateSampleWorkspace()
+   det_info = ws.detectorInfo();
+   mask_count = 0
+   for item in det_info:
+       if not item.isMonitor and item.l2 > 2.0:
+           item.setMasked(True)
+           mask_count += 1
+   print('masked {} detectors'.format(mask_count))
 
-Print detectors with scattering angle
-
-.. code-block:: python 
-
-  from mantid.simpleapi import CreateSampleWorkspace
-
-  # Test workspace with instrument
-  ws = CreateSampleWorkspace()
-  det_info = ws.detectorInfo()
-  for item in det_info:
-      if item.l2 > 0.01:
-         print(item.index) 
+.. testoutput:: mask_detectors
+  
+   masked 200 detectors
+  
-- 
GitLab