test_importer_unittest.py 3.2 KB

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