コード例 #1
0
 def test_set_path(self):
     """
     Setting a path should always store its absolute path, even if a 
     relevant path is given."""
     # Absolute Path Given
     f = File(self.fake_path)
     # Reassign the same path
     f.path = self.fake_path
     self.assertEqual(
         f.path, self.fake_path, msg="The absolute path assert failed"
     )
     
     # Relative Path Given
     #
     # Change the path to just the file's name
     f.path = f.name
     self.assertEqual(
         f.path, self.fake_path, msg="The relative path assert failed"
     )
     
     # Pass a Relative, Non-Normalized Path
     non_normalized_path = "directory1\\directory2\\hello-world.txt"
     expected_path = utils.normalize_path(
         os.path.abspath(non_normalized_path)
     )
     
     f = File(self.fake_path)
     f.path = non_normalized_path
     
     self.assertEqual(
         f.path, expected_path, 
         msg="The relative, non-normalized path assert failed"
     )          
     
     return
コード例 #2
0
 def test_raise_exception_for_setting_path_to_a_directory(self):
     with tempfile.TemporaryDirectory() as td:
         f = File(self.fake_path)
         try:
             f.path = td
         except IsADirectoryError:
             # Do nothing, as this is the right exception to be raised
             pass
         else:
             self.fail("An IsADirectoryError should have been raised")
     
     return