Esempio n. 1
0
 def setUp(self):
     self.padded_atom = atom.render_atom_header(self.type, struct.calcsize('xxxx'))
     self.padded_atom += struct.pack('xxxx')
     
     self.filled_atom = atom.render_atom_header(self.child_type, \
             len(self.child_content))
     self.filled_atom += self.child_content
Esempio n. 2
0
 def setUp(self):
     empty_atom = atom.render_atom_header(self.type, 0)
     self.atom_stream = StringIO.StringIO()
     self.atom_stream.write(empty_atom)
     
     content_atom = atom.render_atom_header(self.type, len(self.content))
     self.atom_stream_with_content = StringIO.StringIO()
     self.atom_stream_with_content.write(content_atom + self.content)
Esempio n. 3
0
 def setUp(self):
     child_atom = atom.render_atom_header(self.child_type, \
         len(self.child_content))
     child_atom += self.child_content
     
     self.rendered_atom = atom.render_atom_header(self.type, len(child_atom))
     self.rendered_atom += child_atom
     
     self.atom_stream = StringIO.StringIO()
     self.atom_stream.write(self.rendered_atom)
     self.atom_stream.seek(0)
Esempio n. 4
0
 def testSaveWithChild(self):
     self.atom.append(self.child_atom)
     save_stream = StringIO.StringIO()
     self.atom.save(save_stream)
     save_stream.seek(0)
     
     rendered_child = atom.render_atom_header(self.child_type, 0)
     rendered_atom = atom.render_atom_header(self.type, len(rendered_child))
     rendered_atom += rendered_child
     
     self.assertEqual(rendered_atom, save_stream.read())
Esempio n. 5
0
 def testSaveEmpty(self):
     save_stream = StringIO.StringIO()
     self.atom.save(save_stream)
     save_stream.seek(0)
     rendered_atom = atom.render_atom_header(self.type, 0)
     
     self.assertEqual(rendered_atom, save_stream.read())
Esempio n. 6
0
 def setUp(self):
     child_padding = atom.ATOM_SPECIAL_CONTAINER_TYPES[self.child_type]['padding']
     child_padding = ''.join(['x' for i in range(child_padding)])
     child_atom = atom.render_atom_header(self.child_type, len(child_padding))
     child_atom += child_padding
     
     atom_padding = atom.ATOM_SPECIAL_CONTAINER_TYPES[self.atom_type]['padding']
     atom_padding = ''.join(['x' for i in range(atom_padding)])
     self.rendered_atom = atom.render_atom_header(self.atom_type, len(atom_padding + child_atom))
     self.rendered_atom += atom_padding + child_atom
     
     init_stream = StringIO.StringIO()
     init_stream.write(self.rendered_atom)
     init_stream.seek(0)
     
     self.atom = atom.Atom(init_stream)
Esempio n. 7
0
 def testSaveWithContent(self):
     self.atom.write(self.content)
     save_stream = StringIO.StringIO()
     self.atom.save(save_stream)
     save_stream.seek(0)
     
     rendered_atom = atom.render_atom_header(self.type, len(self.content))
     rendered_atom += self.content
     
     self.assertEqual(rendered_atom, save_stream.read())
Esempio n. 8
0
 def setUp(self):
     child_atom = atom.render_atom_header(self.initial_child_type, \
         len(self.initial_child_content))
     child_atom += self.initial_child_content
     
     rendered_new_child = atom.render_atom_header(self.new_child_type, \
         len(self.new_child_content)) + self.new_child_content
     new_child_stream = StringIO.StringIO()
     new_child_stream.write(rendered_new_child)
     new_child_stream.seek(0)
     self.new_child_atom = atom.Atom(new_child_stream)
     
     rendered_atom = atom.render_atom_header(self.type, len(child_atom))
     rendered_atom += child_atom
     
     atom_stream = StringIO.StringIO()
     atom_stream.write(rendered_atom)
     atom_stream.seek(0)
     self.atom = atom.Atom(stream=atom_stream)
Esempio n. 9
0
 def testCanSaveAfterAppend(self):
     self.atom.seek(0, os.SEEK_END)
     self.atom.write(self.new_content)
     
     save_stream = StringIO.StringIO()
     self.atom.save(save_stream)
     save_stream.seek(0)
     
     rendered_atom = atom.render_atom_header(self.type, len(self.initial_content) + len(self.new_content))
     rendered_atom += self.initial_content + self.new_content
     
     self.assertEqual(rendered_atom, save_stream.read())
Esempio n. 10
0
 def testOversizeContainerAtom(self):
     rendered_atom = atom.render_atom_header(self.type, \
         len(self.filled_atom) + struct.calcsize('xxxx'))
     rendered_atom += self.filled_atom + struct.pack('xxxx')
     
     atom_stream = StringIO.StringIO()
     atom_stream.write(rendered_atom)
     atom_stream.seek(0)
     loaded_atom = atom.Atom(atom_stream)
     
     self.assertEqual(self.type, loaded_atom.type)
     self.assertEqual(self.child_type, loaded_atom[0].type)
Esempio n. 11
0
 def setUp(self):
     # TODO: Create some kind of atom-tree builder
     child_1_1 = atom.render_atom_header(self.child_1_1_type, \
         len(self.child_1_1_data))
     child_1_1 += self.child_1_1_data
     
     child_1_2 = atom.render_atom_header(self.child_1_2_type, \
         len(self.child_1_2_data))
     child_1_2 += self.child_1_2_data
     
     child_1 = atom.render_atom_header(self.child_1_type, \
         len(child_1_1 + child_1_2))
     child_1 += child_1_1 + child_1_2
     
     child_2 = atom.render_atom_header(self.child_2_type, \
         len(self.child_2_data))
     child_2 += self.child_2_data
     
     self.rendered_atom = atom.render_atom_header(self.root_type, len(child_1 + child_2))
     self.rendered_atom += child_1 + child_2
     
     self.atom_stream = StringIO.StringIO()
     self.atom_stream.write(self.rendered_atom)
     self.atom_stream.seek(0)
Esempio n. 12
0
 def testOversizeInternalAtom(self):
     rendered_atom = atom.render_atom_header(self.type, \
         len(self.padded_atom) + len(self.filled_atom))
     rendered_atom += self.padded_atom + self.filled_atom
     
     atom_stream = StringIO.StringIO()
     atom_stream.write(rendered_atom)
     atom_stream.seek(0)
     
     # Exception if this takes more than 2 seconds
     signal.signal(signal.SIGALRM, self.timeout_handler)
     signal.alarm(2)
     
     loaded_atom = atom.Atom(atom_stream)
     
     self.assertEqual(self.type, loaded_atom.type)
     self.assertEqual(self.type, loaded_atom[0].type)
     self.assertEqual(self.child_type, loaded_atom[1].type)
Esempio n. 13
0
 def setUp(self):
     content_atom = atom.render_atom_header(self.type, len(self.initial_content))
     self.atom_stream = StringIO.StringIO()
     self.atom_stream.write(content_atom + self.initial_content)
     self.atom = atom.Atom(self.atom_stream)