def test_init_end_of_list(self): self.namesize = 0xFF self.file = self.pack() with self.assertRaises(SystemError): DirectoryEntry(self.file, 0) self.namesize = 0x00 self.file = self.pack() with self.assertRaises(SystemError): DirectoryEntry(self.file, 0)
def test_new(self): self.filename = 'NewEntry' self.namesize = len(self.filename) self.attributes = 0 self.cluster = 0 self.filesize = 0 self.file = self.pack() de = DirectoryEntry.new_entry("NewEntry", None) self.assertEqual(self.file, de.pack()) with self.assertRaises(ValueError): DirectoryEntry.new_entry("This name is too long, like, so long, is does not fit in 42 chars", 0)
def test_pack(self): el = DirectoryEntryList(self.data, 0) self.assertEqual(self.data, el.pack()) de = DirectoryEntry.new_entry("New", None) el.append(de) self.assertIn(de.pack(), el.pack())
def test_init_file(self): de = DirectoryEntry(self.file, 0) self.assertEqual(self.filename, de.filename) self.assertFalse(de.atr.READONLY) self.assertFalse(de.atr.HIDDEN) self.assertFalse(de.atr.SYSTEM) self.assertFalse(de.atr.VOLUMELABEL) self.assertFalse(de.atr.DIRECTORY) self.assertFalse(de.atr.ARCHIVE) self.assertFalse(de.atr.DELETED) self.assertEqual(self.filesize, de.size) self.assertEqual(self.cluster, de.cluster) self.assertEqual(self.filename, str(de))
def test_rename(self): de = DirectoryEntry(self.file, 0) with self.assertRaises(ValueError): de.rename("This name is too long, like, so long, is does not fit in 42 chars") test_name = "JFR rocks" de.rename(test_name) self.assertEqual(test_name, de.filename) self.assertEqual(len(test_name), de.namesize)
def test_pack(self): de = DirectoryEntry(self.file, 0) self.assertEqual(self.file, de.pack()) test_name = "JFR rocks" de.rename(test_name) self.filename = test_name self.namesize = len(test_name) self.file = self.pack() self.assertEqual(self.file, de.pack()) de.atr.READONLY = True de.atr.HIDDEN = False de.atr.DIRECTORY = True de.atr.DELETED = True de = DirectoryEntry(de.pack(), 0) self.assertTrue(de.atr.READONLY) self.assertFalse(de.atr.HIDDEN) self.assertTrue(de.atr.DIRECTORY) self.assertTrue(de.atr.DELETED)
def test_append(self): el = DirectoryEntryList(self.data, 0) de = DirectoryEntry.new_entry("New", None) el.append(de) self.assertEqual(101, len(el.list())) self.assertIn(de, el.list())
def test_trailing_data(self): self.data += DirectoryEntry.new_entry("Entry", None).pack() * 5 self.assertEqual(100, len(DirectoryEntryList(self.data, 0)._l))
def test_missing_termination(self): self.data = DirectoryEntry.new_entry("Entry", None).pack() self.data *= 5 with self.assertRaises(SystemError): DirectoryEntryList(self.data, 0)
def setUp(self): self.data = b'' for i in range(0, 100): self.data += DirectoryEntry.new_entry("Entry {:02d}".format(i), None).pack() self.data += b'\xFF' * 64
def test_init_invalid_name(self): self.namesize = 53 self.file = self.pack() with self.assertRaises(SystemError): DirectoryEntry(self.file, 0)
def test_init_wrong_size(self): with self.assertRaises(ValueError): DirectoryEntry(self.file + b'\x00', 0) with self.assertRaises(ValueError): DirectoryEntry(b'\x00', 0)