1dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) 2dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# 3dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# Redistribution and use in source and binary forms, with or without 4dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# modification, are permitted provided that the following conditions 5dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# are met: 6dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# 1. Redistributions of source code must retain the above copyright 7dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# notice, this list of conditions and the following disclaimer. 8dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# 2. Redistributions in binary form must reproduce the above copyright 9dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# notice, this list of conditions and the following disclaimer in the 10dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# documentation and/or other materials provided with the distribution. 11dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# 12dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND 13dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR 16dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 19dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 20dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 21dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 23dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block"""Unit tests for ospath.py.""" 24dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 25dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockimport os 26dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockimport unittest 27dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 28dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockfrom webkitpy.common.system.ospath import relpath 29dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 30dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 31dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# Make sure the tests in this class are platform independent. 32dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockclass RelPathTest(unittest.TestCase): 33dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 34dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block """Tests relpath().""" 35dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 36dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block os_path_abspath = lambda self, path: path 37dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 38dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block def _rel_path(self, path, abs_start_path): 39dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block return relpath(path, abs_start_path, self.os_path_abspath) 40dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 41dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block def test_same_path(self): 42dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block rel_path = self._rel_path("WebKit", "WebKit") 43dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block self.assertEquals(rel_path, "") 44dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 45dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block def test_long_rel_path(self): 46dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block start_path = "WebKit" 47dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block expected_rel_path = os.path.join("test", "Foo.txt") 48dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block path = os.path.join(start_path, expected_rel_path) 49dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 50dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block rel_path = self._rel_path(path, start_path) 51dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block self.assertEquals(expected_rel_path, rel_path) 52dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 53dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block def test_none_rel_path(self): 54dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block """Test _rel_path() with None return value.""" 55dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block start_path = "WebKit" 56dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block path = os.path.join("other_dir", "foo.txt") 57dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 58dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block rel_path = self._rel_path(path, start_path) 59dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block self.assertTrue(rel_path is None) 60dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 61f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch rel_path = self._rel_path("Tools", "WebKit") 62dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block self.assertTrue(rel_path is None) 63