Salome HOME
[bos #36177] [FORUM] - Remove extra-edge on hemisphere
[modules/geom.git] / test / test_perf_01.py
1 from contextlib import contextmanager
2 from datetime import datetime, timedelta
3 from inspect import getfile
4 from os.path import abspath, dirname, join
5 from unittest import TestCase, main
6
7 import salome
8 salome.salome_init_without_session()
9
10 from salome.geom import geomBuilder
11 geom_builder = geomBuilder.New()
12
13 data_dir = abspath(join(dirname(getfile(lambda: None)), 'data'))
14
15 @contextmanager
16 def no_longer_than(seconds):
17     """
18     Context mananger to check that an execution of given code does not
19     exceed maximum expected time.   
20
21     Example of usage:
22
23         with wait(5):
24             do_something_that_should_take_no_more_than_five_seconds()
25
26     Arguments:
27         seconds: max time limit
28
29     Raises:
30         AssertionError: if time limit is exceeded.
31     """
32     expected = timedelta(seconds=seconds)
33     start = datetime.now()
34     yield
35     end = datetime.now()
36     spent = end-start
37     assert spent <= expected, f'Expected maximum delay is exceeded: {spent.total_seconds():.2f} > {seconds:.2f}!'
38
39 class TesselationTest(TestCase):
40     """Test Tesselate() method."""
41
42     def test_performance_01(self):
43         """Check performance of Tesselate() method: case 01."""
44         shape = geom_builder.ImportBREP(join(data_dir, 'test_performance_01.brep'))
45         with no_longer_than(5):
46             geom_builder.Tesselate(shape, 0.17, False, 20)
47
48 if __name__ == "__main__":
49     main()