1 # Copyright (C) 2010 Google Inc. All rights reserved. 2 # 3 # Redistribution and use in source and binary forms, with or without 4 # modification, are permitted provided that the following conditions are 5 # met: 6 # 7 # * Redistributions of source code must retain the above copyright 8 # notice, this list of conditions and the following disclaimer. 9 # * Redistributions in binary form must reproduce the above 10 # copyright notice, this list of conditions and the following disclaimer 11 # in the documentation and/or other materials provided with the 12 # distribution. 13 # * Neither the name of Google Inc. nor the names of its 14 # contributors may be used to endorse or promote products derived from 15 # this software without specific prior written permission. 16 # 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 import unittest 30 import sys 31 32 import path 33 34 class AbspathTest(unittest.TestCase): 35 def assertMatch(self, test_path, expected_uri, 36 platform=None): 37 if platform == 'cygwin' and sys.platform != 'cygwin': 38 return 39 self.assertEqual(path.abspath_to_uri(test_path, platform=platform), 40 expected_uri) 41 42 def test_abspath_to_uri_cygwin(self): 43 if sys.platform != 'cygwin': 44 return 45 46 self.assertMatch('/cygdrive/c/foo/bar.html', 47 'file:///C:/foo/bar.html', 48 platform='cygwin') 49 self.assertEqual(path.abspath_to_uri('/cygdrive/c/foo/bar.html', 50 platform='cygwin'), 51 'file:///C:/foo/bar.html') 52 53 def test_abspath_to_uri_darwin(self): 54 self.assertMatch('/foo/bar.html', 55 'file:///foo/bar.html', 56 platform='darwin') 57 self.assertEqual(path.abspath_to_uri("/foo/bar.html", 58 platform='darwin'), 59 "file:///foo/bar.html") 60 61 def test_abspath_to_uri_linux2(self): 62 self.assertMatch('/foo/bar.html', 63 'file:///foo/bar.html', 64 platform='darwin') 65 self.assertEqual(path.abspath_to_uri("/foo/bar.html", 66 platform='linux2'), 67 "file:///foo/bar.html") 68 69 def test_abspath_to_uri_win(self): 70 self.assertMatch('c:\\foo\\bar.html', 71 'file:///c:/foo/bar.html', 72 platform='win32') 73 self.assertEqual(path.abspath_to_uri("c:\\foo\\bar.html", 74 platform='win32'), 75 "file:///c:/foo/bar.html") 76 77 def test_abspath_to_uri_escaping(self): 78 self.assertMatch('/foo/bar + baz%?.html', 79 'file:///foo/bar%20+%20baz%25%3F.html', 80 platform='darwin') 81 self.assertMatch('/foo/bar + baz%?.html', 82 'file:///foo/bar%20+%20baz%25%3F.html', 83 platform='linux2') 84 85 # Note that you can't have '?' in a filename on windows. 86 self.assertMatch('/cygdrive/c/foo/bar + baz%.html', 87 'file:///C:/foo/bar%20+%20baz%25.html', 88 platform='cygwin') 89 90 def test_stop_cygpath_subprocess(self): 91 if sys.platform != 'cygwin': 92 return 93 94 # Call cygpath to ensure the subprocess is running. 95 path.cygpath("/cygdrive/c/foo.txt") 96 self.assertTrue(path._CygPath._singleton.is_running()) 97 98 # Stop it. 99 path._CygPath.stop_cygpath_subprocess() 100 101 # Ensure that it is stopped. 102 self.assertFalse(path._CygPath._singleton.is_running()) 103 104 if __name__ == '__main__': 105 unittest.main() 106