193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# 393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# Redistribution and use in source and binary forms, with or without 493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# modification, are permitted provided that the following conditions 593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# are met: 693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# 793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# 1. Redistributions of source code must retain the above 893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# copyright notice, this list of conditions and the following 993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# disclaimer. 1093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# 2. Redistributions in binary form must reproduce the above 1193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# copyright notice, this list of conditions and the following 1293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# disclaimer in the documentation and/or other materials 1393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# provided with the distribution. 1493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# 1593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY 1693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE 1993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 2093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 2293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 2493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 2593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# SUCH DAMAGE. 2793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 2893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)import optparse 2993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)import shutil 3093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)import tempfile 31e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)import unittest 3293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 335267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)from webkitpy.common.host_mock import MockHost 345267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)from webkitpy.common.system.filesystem_mock import MockFileSystem 3593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)from webkitpy.common.system.executive_mock import MockExecutive2, ScriptError 3693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)from webkitpy.common.system.outputcapture import OutputCapture 3793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)from webkitpy.w3c.test_importer import TestImporter 3893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 3993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 405267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)FAKE_SOURCE_DIR = '/blink/w3c' 415267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)FAKE_REPO_DIR = '/blink' 425267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 435267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)FAKE_FILES = { 445267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) '/blink/w3c/empty_dir/README.txt': '', 4509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) '/mock-checkout/third_party/WebKit/LayoutTests/w3c/README.txt': '', 4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations': '', 475267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)} 4893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 4993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)class TestImporterTest(unittest.TestCase): 5093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 5193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) def test_import_dir_with_no_tests_and_no_hg(self): 525267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) host = MockHost() 5393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) host.executive = MockExecutive2(exception=OSError()) 545267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) host.filesystem = MockFileSystem(files=FAKE_FILES) 5593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) importer = TestImporter(host, FAKE_SOURCE_DIR, FAKE_REPO_DIR, optparse.Values({"overwrite": False, 'destination': 'w3c', 'ignore_expectations': False})) 5793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 5893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) oc = OutputCapture() 5993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) oc.capture_output() 6093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) try: 6193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) importer.do_import() 6293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) finally: 6393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) oc.restore_output() 6493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 6593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) def test_import_dir_with_no_tests(self): 665267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) host = MockHost() 6793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) host.executive = MockExecutive2(exception=ScriptError("abort: no repository found in '/Volumes/Source/src/wk/Tools/Scripts/webkitpy/w3c' (.hg not found)!")) 685267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) host.filesystem = MockFileSystem(files=FAKE_FILES) 6993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 7009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) importer = TestImporter(host, FAKE_SOURCE_DIR, FAKE_REPO_DIR, optparse.Values({"overwrite": False, 'destination': 'w3c', 'ignore_expectations': False})) 7193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) oc = OutputCapture() 7293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) oc.capture_output() 7393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) try: 7493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) importer.do_import() 7593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) finally: 7693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) oc.restore_output() 7793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 785267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) # FIXME: Needs more tests. 79