Пример #1
0
    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)
Пример #2
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)
Пример #3
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())
Пример #4
0
 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))
Пример #5
0
	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)
Пример #6
0
    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)
Пример #7
0
 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())
Пример #8
0
 def test_trailing_data(self):
     self.data += DirectoryEntry.new_entry("Entry", None).pack() * 5
     self.assertEqual(100, len(DirectoryEntryList(self.data, 0)._l))
Пример #9
0
 def test_missing_termination(self):
     self.data = DirectoryEntry.new_entry("Entry", None).pack()
     self.data *= 5
     with self.assertRaises(SystemError):
         DirectoryEntryList(self.data, 0)
Пример #10
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
Пример #11
0
 def test_init_invalid_name(self):
     self.namesize = 53
     self.file = self.pack()
     with self.assertRaises(SystemError):
         DirectoryEntry(self.file, 0)
Пример #12
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)