예제 #1
0
	def testCopy(self):
		"""make sure, copies are deep"""
		print 'Testing PyUnit: make sure, copies are deep'
		u1 = cp.PyUnit('m')
		u2 = cp.PyUnit(u1)
		u2.unit = 'K'
		self.assertEqual(u1.unit, 'm')
예제 #2
0
	def testSetterTypeSafety(self):
		print 'Testing PyUnit: setter type safety'
		with self.assertRaises(TypeError):
			u = cp.PyUnit()
			u.setU(1)
		with self.assertRaises(UnicodeEncodeError):
			u = cp.PyUnit()
			u.setU(u'\ua000')
예제 #3
0
	def testSetterUnknownUnit(self):
		print 'Testing PyUnit: correct exceptions for unknown units'
		with self.assertRaises(ValueError):
			u = cp.PyUnit('bla')
		with self.assertRaises(ValueError):
			u = cp.PyUnit()
			u.unit = 'bla'
		with self.assertRaises(ValueError):
			u = cp.PyUnit()
			u.setU('bla')
예제 #4
0
	def testSetParameter(self):
		print 'Testing PySource: setting single parameter'
		s = cp.PySource()
		m = cp.PyMeasurement('speed', 12.345, 0.987, 'm/s')
		s.setParameter(m)
		s.setParameter('speed2', 12.345, 0.987, 'm/s')
		s.setParameter('speed3', 12.345, 0.987, cp.PyUnit('m/s'))
예제 #5
0
	def testPrintMode(self):
		print 'Testing PyUnit: print mode'
		u = cp.PyUnit('cm/s')
		self.assertEqual(u.asString(mode=cp.unit_std), '10^-2 m s^-1')
		self.assertEqual(u.asString(mode=cp.unit_exp), '10⁻² m s⁻¹')
예제 #6
0
	def testProperties(self):
		print 'Testing PyUnit: "unit" property getter/setter'
		u = cp.PyUnit('cm')
		self.assertEqual(u.unit, '10^-2 m')
		u.unit = 'm'
		self.assertEqual(u.unit, 'm')
예제 #7
0
	def testSetter(self):
		print 'Testing PyUnit: setter'
		u = cp.PyUnit()
		u.setU('kg')
		u.setU('m')
		u.setU(u'kg')
예제 #8
0
	def testConstructorTypeSafety(self):
		print 'Testing PyUnit: constructor type safety'
		with self.assertRaises(TypeError):
			u = cp.PyUnit(1)
		with self.assertRaises(UnicodeEncodeError):
			u = cp.PyUnit(u'\ua000')
예제 #9
0
	def testConstructor(self):
		print 'Testing PyUnit: constructor'
		u1 = cp.PyUnit()
		u2 = cp.PyUnit('cm')
		u3 = cp.PyUnit(u2)
		u4 = cp.PyUnit(u'cm')
예제 #10
0
	def testSetter(self):
		print 'Testing PyMeasurement: setter'
		m = cp.PyMeasurement()
		m.setM('speed', 12.345, 0.987, 'm/s')
		m.setM('speed', 12.345, 0.987, cp.PyUnit('m/s'))
		m.setM(u'speed', 12.345, 0.987, u'm/s')