示例#1
0
	def test_itemSizeChangedWhileInIncoming(self):
		"""
		If the size of an item changed while it was in Incoming,
		Incoming does *not* go into an inconsistent state (for example,
		thinking that _size is < 0)
		"""
		class LengthChangingString(str):
			def __len__(self2):
				return self2.sayLength

		i = Incoming()
		mutable = LengthChangingString("hi")
		mutable.sayLength = 2
		assert len(mutable) == 2, len(mutable)

		i.give([[1, mutable]])
		sizeBefore = i.getMaxConsumption()
		self.assertTrue(sizeBefore > 0, sizeBefore)

		mutable.sayLength = 3
		assert len(mutable) == 3, len(mutable)

		i.give([[0, "0"]])
		sizeAfter = i.getMaxConsumption()
		self.assertEqual(0, sizeAfter)
示例#2
0
	def test_simple(self):
		i = Incoming()
		_ = i.give([[1, 'string1'], [2, 'string2'], [3, 'string3']])
		self.assertEqual(totalSizeOf('string1') * 3, i.getMaxConsumption())

		_ = i.give([[4, 'string4'], [5, 'string5'], [6, 'string6']])
		self.assertEqual(totalSizeOf('string1') * 6, i.getMaxConsumption())
示例#3
0
	def test_StringFragmentConvertToStr(self):
		"""
		L{StringFragment}s are converted to C{window._wasSF}s if they are
		undeliverable inside L{Incoming}.
		"""
		i = Incoming()
		s = _wasSF("helloworld" * 100)
		sf = StringFragment(s, 0, len(s))
		i.give([[1, sf]])
		self.assertEqual(totalSizeOf(s), i.getMaxConsumption())
示例#4
0
	def test_itemLimit(self):
		i = Incoming()
		self.assertEqual(([], False), i.give([[1, 'string1']], itemLimit=3))
		self.assertEqual(([], False), i.give([[2, 'string2']], itemLimit=3))
		self.assertEqual(([], False), i.give([[3, 'string3']], itemLimit=3))
		self.assertEqual(([], True), i.give([[4, 'string4']], itemLimit=3))
		self.assertEqual(([], True), i.give([[5, 'string5']], itemLimit=3))

		# The items we kept giving it past the limit are dropped to the floor
		deliverable, hitLimit = i.give([[0, 'string0']], itemLimit=3)
		self.assertEqual(False, hitLimit)
		self.assertEqual(['string0', 'string1', 'string2', 'string3'], deliverable)

		self.assertEqual(0, i.getUndeliverableCount())
		self.assertEqual(0, i.getMaxConsumption())
示例#5
0
	def test_noStringsEverGiven(self):
		i = Incoming()
		self.assertEqual(0, i.getMaxConsumption())