mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Patch 1339796: add a relpath() function to os.path.
This commit is contained in:
		
							parent
							
								
									6de691d78c
								
							
						
					
					
						commit
						6f187743ff
					
				
					 7 changed files with 77 additions and 3 deletions
				
			
		|  | @ -2,7 +2,7 @@ | |||
| from test import test_support | ||||
| 
 | ||||
| import posixpath, os | ||||
| from posixpath import realpath, abspath, join, dirname, basename | ||||
| from posixpath import realpath, abspath, join, dirname, basename, relpath | ||||
| 
 | ||||
| # An absolute path to a temporary filename for testing. We can't rely on TESTFN | ||||
| # being an absolute path, so we need this. | ||||
|  | @ -479,6 +479,17 @@ def test_realpath_resolve_first(self): | |||
|                 safe_rmdir(ABSTFN + "/k") | ||||
|                 safe_rmdir(ABSTFN) | ||||
| 
 | ||||
|     def test_relpath(self): | ||||
|         currentdir = os.path.split(os.getcwd())[-1] | ||||
|         self.assertRaises(ValueError, posixpath.relpath, "") | ||||
|         self.assertEqual(posixpath.relpath("a"), "a") | ||||
|         self.assertEqual(posixpath.relpath(os.path.abspath("a")), "a") | ||||
|         self.assertEqual(posixpath.relpath("a/b"), "a/b") | ||||
|         self.assertEqual(posixpath.relpath("../a/b"), "../a/b") | ||||
|         self.assertEqual(posixpath.relpath("a", "../b"), "../"+currentdir+"/a") | ||||
|         self.assertEqual(posixpath.relpath("a/b", "../c"), "../"+currentdir+"/a/b") | ||||
|         self.assertEqual(posixpath.relpath("a", "b/c"), "../../a") | ||||
| 
 | ||||
| def test_main(): | ||||
|     test_support.run_unittest(PosixPathTest) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Collin Winter
						Collin Winter