Add Unittest to commits_for_upload() and fix multiple unittests for several test...
authorjlewis3@apple.com <jlewis3@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Mar 2020 21:08:50 +0000 (21:08 +0000)
committerjlewis3@apple.com <jlewis3@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Mar 2020 21:08:50 +0000 (21:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=208485

Reviewed by Jonathan Bedard.

* Scripts/webkitpy/common/checkout/scm/stub_repository.py:
(StubRepository.__init__): Fixing the constructor to call upon the parent class as we were not doing this before. It also means
that we don't have to recreate the variables that are already created.
* Scripts/webkitpy/common/checkout/scm/stub_repository_unittest.py: High level changed the imports to better reflect what we are using
from each module, rather than making extra imports that we don't need.
(StubRepositoryTest.mock_host_for_stub_repository): Since we are calling both an executive and a filesystem mock for most of the
tests. it makes more sense to create a mock host with the files needed, than it does to instantiate each of these as separate objects
and not part of the host.
(StubRepositoryTest.test_in_working_directory): Changed the filesystem call to the host call.
(StubRepositoryTest.test_native_revision): Changed the filesystem call to the host call.
(StubRepositoryTest.test_native_branch): Changed the filesystem call to the host call.
(StubRepositoryTest.test_svn_revision): Changed the filesystem call to the host call.
(StubRepositoryTest.test_find_checkout_root): Changed the filesystem call to the host call.
(StubRepositoryTest.test_find_checkout_root_failure): Changed the filesystem call to the host call.
(StubRepositoryTest.test_find_parent_path_matching_callback_condition_with_file_system): Changed the filesystem call to the host call.
* Scripts/webkitpy/layout_tests/models/test_run_results_unittest.py:
(SummarizedResultsTest.test_svn_revision_exists): Changed the name to original test to better reflect that it was just looking to see
if we were geting any value at all
(SummarizedResultsTest.test_svn_revision): Added a test to make sure that the revision we are getting is what we expect to get and make
sure we aren't gabking the wrong key:value pair
* Scripts/webkitpy/port/base_unittest.py: Changed from MockSystemHost to MockHost as we want the extras that
come with the MockHosts and MockHost inherits from MockSystemHost.
(PortTest.make_port): Changed the port to call MockHost that will creat the required stub_repository files.
(test_commits_for_upload): Added amissing test for commits_for_upload as this has been an issue when trying to make changes
to the various upload steps.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@257796 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/common/checkout/scm/stub_repository.py
Tools/Scripts/webkitpy/common/checkout/scm/stub_repository_unittest.py
Tools/Scripts/webkitpy/layout_tests/models/test_run_results_unittest.py
Tools/Scripts/webkitpy/port/base_unittest.py

index 6f64c5b..7008f2b 100644 (file)
@@ -1,3 +1,36 @@
+2020-03-03  Matt Lewis  <jlewis3@apple.com>
+
+        Add Unittest to commits_for_upload() and fix multiple unittests for several test suites.
+        https://bugs.webkit.org/show_bug.cgi?id=208485
+
+        Reviewed by Jonathan Bedard.
+
+        * Scripts/webkitpy/common/checkout/scm/stub_repository.py:
+        (StubRepository.__init__): Fixing the constructor to call upon the parent class as we were not doing this before. It also means
+        that we don't have to recreate the variables that are already created.
+        * Scripts/webkitpy/common/checkout/scm/stub_repository_unittest.py: High level changed the imports to better reflect what we are using
+        from each module, rather than making extra imports that we don't need.
+        (StubRepositoryTest.mock_host_for_stub_repository): Since we are calling both an executive and a filesystem mock for most of the
+        tests. it makes more sense to create a mock host with the files needed, than it does to instantiate each of these as separate objects
+        and not part of the host.
+        (StubRepositoryTest.test_in_working_directory): Changed the filesystem call to the host call.
+        (StubRepositoryTest.test_native_revision): Changed the filesystem call to the host call.
+        (StubRepositoryTest.test_native_branch): Changed the filesystem call to the host call.
+        (StubRepositoryTest.test_svn_revision): Changed the filesystem call to the host call.
+        (StubRepositoryTest.test_find_checkout_root): Changed the filesystem call to the host call.
+        (StubRepositoryTest.test_find_checkout_root_failure): Changed the filesystem call to the host call.
+        (StubRepositoryTest.test_find_parent_path_matching_callback_condition_with_file_system): Changed the filesystem call to the host call.
+        * Scripts/webkitpy/layout_tests/models/test_run_results_unittest.py: 
+        (SummarizedResultsTest.test_svn_revision_exists): Changed the name to original test to better reflect that it was just looking to see
+        if we were geting any value at all
+        (SummarizedResultsTest.test_svn_revision): Added a test to make sure that the revision we are getting is what we expect to get and make
+        sure we aren't gabking the wrong key:value pair
+        * Scripts/webkitpy/port/base_unittest.py: Changed from MockSystemHost to MockHost as we want the extras that
+        come with the MockHosts and MockHost inherits from MockSystemHost.
+        (PortTest.make_port): Changed the port to call MockHost that will creat the required stub_repository files.
+        (test_commits_for_upload): Added amissing test for commits_for_upload as this has been an issue when trying to make changes
+        to the various upload steps.
+
 2020-03-03  Aakash Jain  <aakash_jain@apple.com>
 
         [ews] Add build step to find list of modified changelogs
index 3bb91e2..ce49e1a 100644 (file)
@@ -37,10 +37,8 @@ _log = logging.getLogger(__name__)
 class StubRepository(SCM):
     _stub_repository_json = 'checkout_information.json'
 
-    def __init__(self, cwd, filesystem, **kwargs):
-        # We create our own checkout root and filesystem here because we are working around the fact that we don't have and actual SCM scheme.
-        self._filesystem = filesystem
-        self.checkout_root = self.find_checkout_root(cwd)
+    def __init__(self, cwd, patch_directories=None, **kwargs):
+        SCM.__init__(self, cwd, **kwargs)
 
     @classmethod
     def _find_parent_path_matching_callback_condition(cls, path, callback, filesystem=None):
index 426df1b..dcb4b1b 100644 (file)
@@ -22,7 +22,9 @@
 
 import unittest
 
-from webkitpy.common.system import filesystem_mock
+from webkitpy.common.system.filesystem_mock import MockFileSystem
+from webkitpy.common.system.executive_mock import MockExecutive
+from webkitpy.common.host_mock import MockHost
 from webkitpy.common.checkout.scm.stub_repository import StubRepository
 
 mock_stub_repository_json = {'branch': 'trunk', 'id': '2738499'}
@@ -38,41 +40,43 @@ class StubRepositoryTest(unittest.TestCase):
 
     @staticmethod
     def mock_host_for_stub_repository():
-        host = filesystem_mock.MockFileSystem(files=FAKE_FILES)
+        host = MockHost(create_stub_repository_files=True)
+        host.filesystem = MockFileSystem(files=FAKE_FILES)
+        host.executive = MockExecutive()
         return host
 
     def test_in_working_directory(self):
         host = StubRepositoryTest.mock_host_for_stub_repository()
-        self.assertTrue(StubRepository.in_working_directory(path=host.join(host.getcwd(), 'TestDirectory', 'TestDirectory2', 'TestDirectory3'), filesystem=host))
+        self.assertTrue(StubRepository.in_working_directory(path=host.filesystem.join(host.filesystem.getcwd(), 'TestDirectory', 'TestDirectory2', 'TestDirectory3'), filesystem=host.filesystem))
 
     def test_native_revision(self):
         host = StubRepositoryTest.mock_host_for_stub_repository()
-        repository = StubRepository(cwd=host.getcwd(), filesystem=host)
-        self.assertEqual(repository.native_revision(path=host.join(host.getcwd(), 'TestDirectory', 'TestDirectory2', 'TestDirectory3')), mock_stub_repository_json['id'])
+        repository = StubRepository(cwd=host.filesystem.getcwd(), filesystem=host.filesystem, executive=host.executive)
+        self.assertEqual(repository.native_revision(path=host.filesystem.join(host.filesystem.getcwd(), 'TestDirectory', 'TestDirectory2', 'TestDirectory3')), mock_stub_repository_json['id'])
 
     def test_native_branch(self):
         host = StubRepositoryTest.mock_host_for_stub_repository()
-        repository = StubRepository(cwd=host.getcwd(), filesystem=host)
-        self.assertEqual(repository.native_branch(path=host.join(host.getcwd(), 'TestDirectory', 'TestDirectory2', 'TestDirectory3')), mock_stub_repository_json['branch'])
+        repository = StubRepository(cwd=host.filesystem.getcwd(), filesystem=host.filesystem, executive=host.executive)
+        self.assertEqual(repository.native_branch(path=host.filesystem.join(host.filesystem.getcwd(), 'TestDirectory', 'TestDirectory2', 'TestDirectory3')), mock_stub_repository_json['branch'])
 
     def test_svn_revision(self):
         host = StubRepositoryTest.mock_host_for_stub_repository()
-        repository = StubRepository(cwd=host.getcwd(), filesystem=host)
-        self.assertEqual(repository.svn_revision(path=host.join(host.getcwd(), 'TestDirectory', 'TestDirectory2', 'TestDirectory3')), mock_stub_repository_json['id'])
+        repository = StubRepository(cwd=host.filesystem.getcwd(), filesystem=host.filesystem, executive=host.executive)
+        self.assertEqual(repository.svn_revision(path=host.filesystem.join(host.filesystem.getcwd(), 'TestDirectory', 'TestDirectory2', 'TestDirectory3')), mock_stub_repository_json['id'])
 
     def test_find_checkout_root(self):
         host = StubRepositoryTest.mock_host_for_stub_repository()
-        repository = StubRepository(cwd=host.getcwd(), filesystem=host)
-        self.assertEquals(repository.find_checkout_root(path=host.join('TestDirectory', 'TestDirectory2', 'TestDirectory3')), host.join(host.getcwd(), 'TestDirectory', 'TestDirectory2'))
+        repository = StubRepository(cwd=host.filesystem.getcwd(), filesystem=host.filesystem, executive=host.executive)
+        self.assertEquals(repository.find_checkout_root(path=host.filesystem.join('TestDirectory', 'TestDirectory2', 'TestDirectory3')), host.filesystem.join(host.filesystem.getcwd(), 'TestDirectory', 'TestDirectory2'))
 
     def test_find_checkout_root_failure(self):
         host = StubRepositoryTest.mock_host_for_stub_repository()
-        repository = StubRepository(cwd=host.getcwd(), filesystem=host)
-        self.assertIsNone(repository.find_checkout_root(path=host.getcwd()))
+        repository = StubRepository(cwd=host.filesystem.getcwd(), filesystem=host.filesystem, executive=host.executive)
+        self.assertIsNone(repository.find_checkout_root(path=host.filesystem.getcwd()))
 
     def test_find_parent_path_matching_callback_condition_with_file_system(self):
         host = StubRepositoryTest.mock_host_for_stub_repository()
-        self.assertIsNone(StubRepository._find_parent_path_matching_callback_condition(path=host.join('TestDirectory'), callback=lambda path: True, filesystem=host))
+        self.assertIsNone(StubRepository._find_parent_path_matching_callback_condition(path=host.filesystem.join('TestDirectory'), callback=lambda path: True, filesystem=host.filesystem))
 
     def test_find_parent_path_matching_callback_condition_without_file_system(self):
         self.assertIsNone(StubRepository._find_parent_path_matching_callback_condition(path='/Volumes/', callback=lambda path: True, filesystem=None))
index d5acb0e..09501aa 100644 (file)
@@ -154,11 +154,16 @@ class SummarizedResultsTest(unittest.TestCase):
         summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
         self.assertNotIn('revision', summary)
 
-    def test_svn_revision(self):
+    def test_svn_revision_exists(self):
         self.port._options.builder_name = 'dummy builder'
         summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
         self.assertNotEquals(summary['revision'], '')
 
+    def test_svn_revision(self):
+        self.port._options.builder_name = 'dummy builder'
+        summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
+        self.assertEquals(summary['revision'], '2738499')
+
     def test_summarized_results_wontfix(self):
         self.port._options.builder_name = 'dummy builder'
         summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
index 5df1cc5..7a188a2 100644 (file)
@@ -36,6 +36,7 @@ from webkitpy.common.system.filesystem_mock import MockFileSystem
 from webkitpy.common.system.outputcapture import OutputCapture
 from webkitpy.common.system.executive_mock import MockExecutive2
 from webkitpy.common.system.systemhost_mock import MockSystemHost
+from webkitpy.common.host_mock import MockHost
 
 from webkitpy.port import Port
 from webkitpy.port.test import add_unit_tests_to_mock_filesystem, TestPort
@@ -46,7 +47,7 @@ def cmp(a, b):
 
 class PortTest(unittest.TestCase):
     def make_port(self, executive=None, with_tests=False, port_name=None, **kwargs):
-        host = MockSystemHost()
+        host = MockHost(create_stub_repository_files=True)
         if executive:
             host.executive = executive
         if with_tests:
@@ -435,6 +436,10 @@ class PortTest(unittest.TestCase):
             port.reference_files('fast/ref.html'),
         )
 
+    def test_commits_for_upload(self):
+        port = self.make_port(port_name='foo')
+        self.assertEqual([{'repository_id': 'webkit', 'id': '2738499', 'branch': 'trunk'}], port.commits_for_upload())
+
 
 class NaturalCompareTest(unittest.TestCase):
     def setUp(self):