Beispiel #1
0
	def test_decodeInt(self):
		""" bdecode a random number of bencoded integer strings (fewer than 100) containing random
			integer values (less than one million) and ensure that the decoding gives us the proper
			integer result
		"""
		for i in range(0, 100):
			num = random.randint(0,1000000)
			self.assertEqual(int(bdecode.decode("".join(["i", str(num), "e"]))['data']), num)
Beispiel #2
0
	def __init__(self, torrentfile):
		""" To init we open the file that belongs to the supplied path,
		read in the entire contents, close the file, and then decode the contents
		and keep the decoded version around for later reference.
		"""
		file = open(torrentfile, "r")
		contents = file.read()
		file.close()
		self.data = bdecode.decode(contents)["data"]
Beispiel #3
0
 def test_encode_decodeing(self):
     for i in range(len(test_raw_values)):
         res = decode(encode(test_raw_values[i]))
         self.assertEqual(res, test_raw_values[i])
Beispiel #4
0
 def test_decodeSimpleDict(self):
     unencodedDict = {"first":"string","second":10}
     encodedDict = "d5:first6:string6:secondi10ee" 
     self.assertEqual(bdecode.decode(encodedDict)['data'], unencodedDict)
Beispiel #5
0
 def test_decodeSimpleList(self):
     unencodedList = ["string", 10]
     encodedList = "l6:stringi10ee"
     self.assertEqual(bdecode.decode(encodedList)['data'],unencodedList)
Beispiel #6
0
	def test_encode_decode_String(self):
		""" test that beconding a string, and bdecoding the result, ends up in the initial string """
		for key in self.strings:
			self.assertEqual(bdecode.decode(bencode.encode(key))['data'], key)
Beispiel #7
0
	def test_decodeString(self):
		""" test that we bdecode a bencoded string into the correct value string """
		for key in self.strings:
			decoded_string = bdecode.decode(self.strings[key])
			self.assertEqual(decoded_string['data'], key)