ProgressTest.py 1.57 KB
Newer Older
1
2
3
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
#   NScD Oak Ridge National Laboratory, European Spallation Source,
#   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
# SPDX - License - Identifier: GPL - 3.0 +
7
8
9
10
import unittest
from mantid.api import Progress,PythonAlgorithm
from mantid.kernel import ProgressBase

11

12
13
14
15
16
17
18
class ProgressTest(unittest.TestCase):

    def test_class_inherits_ProgressBase(self):
        self.assertTrue(issubclass(Progress,ProgressBase))

    def test_object_can_be_constructed_with_PythonAlgorithm(self):
        class ProgressConstructTestAlgorithm(PythonAlgorithm):
19

20
21
22
23
24
25
            def PyInit(self):
                pass
            def PyExec(self):
                prog_reporter = Progress(self,0.0,1.0,100)
                if not isinstance(prog_reporter, Progress):
                    raise RuntimeError("Object constructed but it is not of the correct type!")
26

27
28
29
30
31
32
33
        # Test
        test_alg = ProgressConstructTestAlgorithm()
        test_alg.initialize()
        test_alg.execute()

    def test_object_can_be_successfully_report_with_PythonAlgorithm(self):
        class ProgressReportTestAlgorithm(PythonAlgorithm):
34

35
36
37
38
39
40
41
42
43
44
45
46
47
            def PyInit(self):
                pass
            def PyExec(self):
                prog_reporter = Progress(self,0.0,1.0,100)
                prog_reporter.report()
        # Test
        test_alg = ProgressReportTestAlgorithm()
        test_alg.initialize()
        test_alg.execute()


if __name__ == '__main__':
    unittest.main()