1 # Copyright (C) 2013 Adobe Systems Incorporated. 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 5 # are met: 6 # 7 # 1. Redistributions of source code must retain the above 8 # copyright notice, this list of conditions and the following 9 # disclaimer. 10 # 2. Redistributions in binary form must reproduce the above 11 # copyright notice, this list of conditions and the following 12 # disclaimer in the documentation and/or other materials 13 # provided with the distribution. 14 # 15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY 16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE 19 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 20 # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 24 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 25 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 # SUCH DAMAGE. 27 28 import optparse 29 import shutil 30 import tempfile 31 import unittest 32 33 from webkitpy.common.host_mock import MockHost 34 from webkitpy.common.system.filesystem_mock import MockFileSystem 35 from webkitpy.common.system.executive_mock import MockExecutive2, ScriptError 36 from webkitpy.common.system.outputcapture import OutputCapture 37 from webkitpy.w3c.test_importer import TestImporter 38 39 40 FAKE_SOURCE_DIR = '/blink/w3c' 41 FAKE_REPO_DIR = '/blink' 42 43 FAKE_FILES = { 44 '/blink/w3c/empty_dir/README.txt': '', 45 '/mock-checkout/third_party/WebKit/LayoutTests/w3c/README.txt': '', 46 '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations': '', 47 } 48 49 class TestImporterTest(unittest.TestCase): 50 51 def test_import_dir_with_no_tests_and_no_hg(self): 52 host = MockHost() 53 host.executive = MockExecutive2(exception=OSError()) 54 host.filesystem = MockFileSystem(files=FAKE_FILES) 55 56 importer = TestImporter(host, FAKE_SOURCE_DIR, FAKE_REPO_DIR, optparse.Values({"overwrite": False, 'destination': 'w3c', 'ignore_expectations': False})) 57 58 oc = OutputCapture() 59 oc.capture_output() 60 try: 61 importer.do_import() 62 finally: 63 oc.restore_output() 64 65 def test_import_dir_with_no_tests(self): 66 host = MockHost() 67 host.executive = MockExecutive2(exception=ScriptError("abort: no repository found in '/Volumes/Source/src/wk/Tools/Scripts/webkitpy/w3c' (.hg not found)!")) 68 host.filesystem = MockFileSystem(files=FAKE_FILES) 69 70 importer = TestImporter(host, FAKE_SOURCE_DIR, FAKE_REPO_DIR, optparse.Values({"overwrite": False, 'destination': 'w3c', 'ignore_expectations': False})) 71 oc = OutputCapture() 72 oc.capture_output() 73 try: 74 importer.do_import() 75 finally: 76 oc.restore_output() 77 78 # FIXME: Needs more tests. 79