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')
	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')
	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')
	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'))
	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⁻¹')
	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')
	def testSetter(self):
		print 'Testing PyUnit: setter'
		u = cp.PyUnit()
		u.setU('kg')
		u.setU('m')
		u.setU(u'kg')
	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')
	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')