Пример #1
0
 def test_equality(self):
     """Test the __eq__ and __ne__ operators."""
     entry_from_path = FileOnDisk(self.input_ovf)
     entry_from_dir_plus_name = FileOnDisk(
         os.path.dirname(self.input_ovf),
         os.path.basename(self.input_ovf))
     self.assertEqual(entry_from_path, entry_from_dir_plus_name)
     other_entry = FileOnDisk(self.input_vmdk)
     self.assertNotEqual(entry_from_path, other_entry)
Пример #2
0
 def test_open(self):
     """Test the open() API."""
     ref = FileOnDisk(os.path.dirname(self.input_ovf),
                      os.path.basename(self.input_ovf))
     with ref.open('r') as ref_obj:
         file_obj = open(self.input_ovf, 'r')
         try:
             self.assertEqual(file_obj.readline(), ref_obj.readline())
         finally:
             file_obj.close()
     # ref_obj should be closed automatically
     self.assertRaises(ValueError, ref_obj.read)
Пример #3
0
 def test_open_close(self):
     """Test the open() and close() APIs."""
     ref = FileOnDisk(self.input_ovf)
     ref_obj = ref.open('r')
     try:
         file_obj = open(self.input_ovf, 'r')
         try:
             self.assertEqual(file_obj.readline(), ref_obj.readline())
         finally:
             file_obj.close()
     finally:
         ref.close()
Пример #4
0
 def test_open_close(self):
     """Test the open() and close() APIs."""
     ref = FileOnDisk(self.input_ovf)
     ref_obj = ref.open('r')
     try:
         file_obj = open(self.input_ovf, 'r')
         try:
             self.assertEqual(file_obj.readline(), ref_obj.readline())
         finally:
             file_obj.close()
     finally:
         ref.close()
Пример #5
0
 def test_add_to_archive(self):
     """Test the add_to_archive() API."""
     output_tarfile = os.path.join(self.temp_dir, 'test_output.tar')
     with closing(tarfile.open(output_tarfile, 'w')) as tarf:
         FileOnDisk(self.input_ovf).add_to_archive(tarf)
     with closing(tarfile.open(output_tarfile, 'r')) as tarf:
         tarf.extract('input.ovf', self.temp_dir)
     self.check_diff("", file2=os.path.join(self.temp_dir, 'input.ovf'))
Пример #6
0
 def test_size(self):
     """Test the size property."""
     self.assertEqual(FileOnDisk(os.path.dirname(self.input_ovf),
                                 os.path.basename(self.input_ovf)).size,
                      os.path.getsize(self.input_ovf))
Пример #7
0
 def test_exists_relative(self):
     """Test like test_exists, but with a relative path."""
     os.chdir(os.path.dirname(self.input_ovf))
     self.assertTrue(FileOnDisk('',
                                os.path.basename(self.input_ovf)).exists)
     self.assertLogged(**self.FILE_REF_RELATIVE)
Пример #8
0
 def test_exists(self):
     """Test the exists property."""
     self.assertTrue(FileOnDisk(os.path.dirname(self.input_ovf),
                                os.path.basename(self.input_ovf)).exists)
Пример #9
0
 def test_copy_to(self):
     """Test the copy_to() API."""
     FileOnDisk(os.path.dirname(self.input_ovf),
                os.path.basename(self.input_ovf)).copy_to(self.temp_dir)
     self.check_diff("", file2=os.path.join(self.temp_dir, 'input.ovf'))
Пример #10
0
 def test_exists(self):
     """Test the exists property."""
     self.assertTrue(FileOnDisk(self.input_ovf).exists)