File: enumTest.py

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (41 lines) | stat: -rw-r--r-- 1,495 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import unittest, yade


class TestEnum(unittest.TestCase):

	def setUp(self):
		if self.canTest():  # to test if assignment of enums works properly we need any kind enum.
			self.r = yade.OpenGLRenderingEngine()
		else:
			pass

	def tearDown(self):
		pass  # here finalize the tests, maybe close an opened file, or something else

	def canTest(self):
		return 'QT5' in yade.config.features

	def thisTestsException1(self):
		self.r.blinkHighlight = -100

	def thisTestsException2(self):
		self.r.blinkHighlight = 'incorrect string'

	def testException(self):
		if (not self.canTest()):
			return
		# make sure it's impossible to assign incorrect values.
		print("\n  Here it must throw two exceptions:")
		self.assertRaises(TypeError, self.thisTestsException1)
		self.assertRaises(TypeError, self.thisTestsException2)

	def testAssignment(self):
		if (not self.canTest()):
			return
		# This is not to test if useSolver by default equals CholeskyFactorization, if you need to change the default then change the test here. Or test a different eum.
		# Because this is to test function ArbitraryEnum_from_python<…> if assignment to any enum works as expected and if it throws when it should.
		self.assertTrue(self.r.blinkHighlight == yade.EnumClass_BlinkHighlight.NORMAL)
		self.r.blinkHighlight = 'NEVER'
		self.assertTrue(self.r.blinkHighlight == yade.EnumClass_BlinkHighlight.NEVER)
		self.r.blinkHighlight = 2
		self.assertTrue(self.r.blinkHighlight == yade.EnumClass_BlinkHighlight.WEAK)