Ejemplo n.º 1
0
 def test_set_path(self):
     # Absolute Path Given
     d = Directory(self.fake_path)
     # Reassign the same path
     d.path = self.fake_path
     self.assertEqual(
         d.path, self.fake_path, msg="The absolute path assert failed"
     )
     
     # Relative Path Given
     #
     # Change the path to just the directory's name
     d.path = d.name
     self.assertEqual(
         d.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)
     )
     
     d = Directory(self.fake_path)
     d.path = non_normalized_path
     
     self.assertEqual(
         d.path, expected_path, 
         msg="The relative, non-normalized path assert failed"
     )          
     
     return   
Ejemplo n.º 2
0
 def test_raise_exception_for_setting_path_to_a_file(self):
     d = Directory(self.fake_path)
     with tempfile.NamedTemporaryFile() as tf:
         try:
             d.path = tf.name
         except NotADirectoryError:
             # Do nothing, as this is the right exception to be raised
             pass
         else:
             self.fail("A NotADirectoryError should have been raised")
     
     return