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