Diff
Modified: trunk/Tools/ChangeLog (279346 => 279347)
--- trunk/Tools/ChangeLog 2021-06-28 19:56:01 UTC (rev 279346)
+++ trunk/Tools/ChangeLog 2021-06-28 19:57:15 UTC (rev 279347)
@@ -1,5 +1,36 @@
2021-06-28 Jonathan Bedard <jbed...@apple.com>
+ [webkitcorepy] Add test suite with temp directory
+ https://bugs.webkit.org/show_bug.cgi?id=227327
+ <rdar://problem/79697909>
+
+ Reviewed by Stephanie Lewis.
+
+ We had some duplicated code which set up, then cleaned up a temporary
+ directory associated with a test. This should really be owned by a
+ base class shared between multiple test suites.
+
+ * Scripts/libraries/webkitcorepy/setup.py: Bump version.
+ * Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py: Ditto.
+ * Scripts/libraries/webkitcorepy/webkitcorepy/testing.py: Added.
+ (PathTestCase): Create a temporary directory before a test starts, delete it after.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/test/canonicalize_unittest.py:
+ (TestCanonicalize): Adopt PathTestCase.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/test/checkout_unittest.py:
+ (TestCheckout): Adopt PathTestCase.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py:
+ (TestFind): Adopt PathTestCase.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py:
+ (TestGit): Adopt PathTestCase.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/test/scm_unittest.py:
+ (TestScm): Adopt PathTestCase.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py:
+ (TestSetupGitSvn): Adopt PathTestCase.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py:
+ (TestLocalSvn): Adopt PathTestCase.
+
+2021-06-28 Jonathan Bedard <jbed...@apple.com>
+
[webkitcorepy] Fix race condition in TaskPool unittests
https://bugs.webkit.org/show_bug.cgi?id=227455
<rdar://problem/79873003>
Modified: trunk/Tools/Scripts/libraries/webkitcorepy/setup.py (279346 => 279347)
--- trunk/Tools/Scripts/libraries/webkitcorepy/setup.py 2021-06-28 19:56:01 UTC (rev 279346)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/setup.py 2021-06-28 19:57:15 UTC (rev 279347)
@@ -30,7 +30,7 @@
setup(
name='webkitcorepy',
- version='0.5.19',
+ version='0.6.0',
description='Library containing various Python support classes and functions.',
long_description=readme(),
classifiers=[
Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py (279346 => 279347)
--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py 2021-06-28 19:56:01 UTC (rev 279346)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py 2021-06-28 19:57:15 UTC (rev 279347)
@@ -37,7 +37,7 @@
from webkitcorepy.task_pool import TaskPool
from webkitcorepy.credentials import credentials
-version = Version(0, 5, 19)
+version = Version(0, 6, 0)
from webkitcorepy.autoinstall import Package, AutoInstall
if sys.version_info > (3, 0):
Copied: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/testing.py (from rev 279346, trunk/Tools/Scripts/libraries/webkitcorepy/setup.py) (0 => 279347)
--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/testing.py (rev 0)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/testing.py 2021-06-28 19:57:15 UTC (rev 279347)
@@ -0,0 +1,48 @@
+# Copyright (C) 2021 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from __future__ import absolute_import
+
+import os
+import shutil
+import tempfile
+
+from unittest import TestCase
+
+
+class PathTestCase(TestCase):
+ basepath = ''
+
+ def __init__(self, *args, **kwargs):
+ super(PathTestCase, self).__init__(*args, **kwargs)
+ self.container = None
+ self.path = None
+
+ def setUp(self):
+ self.container = tempfile.mkdtemp()
+ self.path = os.path.join(self.container, self.basepath)
+ os.makedirs(self.path)
+
+ def tearDown(self):
+ shutil.rmtree(self.container, ignore_errors=True)
+ self.container = None
+ self.path = None
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/canonicalize_unittest.py (279346 => 279347)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/canonicalize_unittest.py 2021-06-28 19:56:01 UTC (rev 279346)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/canonicalize_unittest.py 2021-06-28 19:57:15 UTC (rev 279347)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 Apple Inc. All rights reserved.
+# Copyright (C) 2020-2021 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -20,16 +20,21 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-import unittest
+import os
-from webkitcorepy import OutputCapture
+from webkitcorepy import OutputCapture, testing
from webkitcorepy.mocks import Time as MockTime
from webkitscmpy import program, mocks, local, Commit, Contributor
-class TestCanonicalize(unittest.TestCase):
- path = '/mock/repository'
+class TestCanonicalize(testing.PathTestCase):
+ basepath = 'mock/repository'
+ def setUp(self):
+ super(TestCanonicalize, self).setUp()
+ os.mkdir(os.path.join(self.path, '.git'))
+ os.mkdir(os.path.join(self.path, '.svn'))
+
def test_invalid(self):
with OutputCapture(), mocks.local.Git(), mocks.local.Svn(self.path), MockTime:
self.assertEqual(1, program.main(
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/checkout_unittest.py (279346 => 279347)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/checkout_unittest.py 2021-06-28 19:56:01 UTC (rev 279346)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/checkout_unittest.py 2021-06-28 19:57:15 UTC (rev 279347)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 Apple Inc. All rights reserved.
+# Copyright (C) 2020-2021 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -20,16 +20,21 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-import unittest
+import os
-from webkitcorepy import OutputCapture
+from webkitcorepy import OutputCapture, testing
from webkitcorepy.mocks import Time as MockTime
from webkitscmpy import program, mocks, local
-class TestCheckout(unittest.TestCase):
- path = '/mock/repository'
+class TestCheckout(testing.PathTestCase):
+ basepath = 'mock/repository'
+ def setUp(self):
+ super(TestCheckout, self).setUp()
+ os.mkdir(os.path.join(self.path, '.git'))
+ os.mkdir(os.path.join(self.path, '.svn'))
+
def test_checkout_git(self):
with OutputCapture(), mocks.local.Git(self.path), mocks.local.Svn(), MockTime:
self.assertEqual('d8bce26fa65c6fc8f39c17927abb77f69fab82fc', local.Git(self.path).commit().hash)
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py (279346 => 279347)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py 2021-06-28 19:56:01 UTC (rev 279346)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py 2021-06-28 19:57:15 UTC (rev 279347)
@@ -21,19 +21,24 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import json
+import os
import shutil
import tempfile
-import unittest
from datetime import datetime
-from webkitcorepy import OutputCapture
+from webkitcorepy import OutputCapture, testing
from webkitcorepy.mocks import Time as MockTime
from webkitscmpy import program, mocks
-class TestFind(unittest.TestCase):
- path = '/mock/repository'
+class TestFind(testing.PathTestCase):
+ basepath = 'mock/repository'
+ def setUp(self):
+ super(TestFind, self).setUp()
+ os.mkdir(os.path.join(self.path, '.git'))
+ os.mkdir(os.path.join(self.path, '.svn'))
+
def test_basic_git(self):
with OutputCapture() as captured, mocks.local.Git(self.path), mocks.local.Svn(), MockTime:
self.assertEqual(0, program.main(
@@ -235,7 +240,7 @@
)
-class TestInfo(unittest.TestCase):
+class TestInfo(testing.TestCase):
path = '/mock/repository'
def test_basic_git(self):
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py (279346 => 279347)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py 2021-06-28 19:56:01 UTC (rev 279346)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py 2021-06-28 19:57:15 UTC (rev 279347)
@@ -21,19 +21,20 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
-import shutil
-import tempfile
-import unittest
from datetime import datetime
-from webkitcorepy import run, LoggerCapture, OutputCapture
+from webkitcorepy import run, testing, LoggerCapture, OutputCapture
from webkitcorepy.mocks import Time as MockTime
from webkitscmpy import Commit, local, mocks, remote
-class TestGit(unittest.TestCase):
- path = '/mock/repository'
+class TestGit(testing.PathTestCase):
+ basepath = 'mock/repository'
+ def setUp(self):
+ super(TestGit, self).setUp()
+ os.mkdir(os.path.join(self.path, '.git'))
+
def test_detection(self):
with OutputCapture(), mocks.local.Git(self.path), mocks.local.Svn():
detect = local.Scm.from_path(self.path)
@@ -79,65 +80,52 @@
self.assertEqual(local.Git(self.path).default_branch, 'main')
def test_scm_type(self):
- try:
- dirname = tempfile.mkdtemp()
- with mocks.local.Git(dirname, remote='g...@example.org:{}'.format(self.path)), MockTime, LoggerCapture():
- self.assertTrue(local.Git(dirname).is_git)
- self.assertFalse(local.Git(dirname).is_svn)
+ with mocks.local.Git(self.path, remote='g...@example.org:{}'.format(self.path)), MockTime, LoggerCapture():
+ self.assertTrue(local.Git(self.path).is_git)
+ self.assertFalse(local.Git(self.path).is_svn)
- with mocks.local.Git(dirname, git_svn=True, remote='g...@example.org:{}'.format(self.path)), MockTime, LoggerCapture():
- self.assertTrue(local.Git(dirname).is_git)
- self.assertTrue(local.Git(dirname).is_svn)
+ with mocks.local.Git(self.path, git_svn=True, remote='g...@example.org:{}'.format(self.path)), MockTime, LoggerCapture():
+ self.assertTrue(local.Git(self.path).is_git)
+ self.assertTrue(local.Git(self.path).is_svn)
- finally:
- shutil.rmtree(dirname)
-
def test_info(self):
- try:
- dirname = tempfile.mkdtemp()
- with mocks.local.Git(dirname, remote='g...@example.org:{}'.format(self.path)), MockTime, LoggerCapture():
- with self.assertRaises(local.Git.Exception):
- self.assertEqual(dict(), local.Git(dirname).info())
+ with mocks.local.Git(self.path, remote='g...@example.org:mock/repository'), MockTime, LoggerCapture():
+ with self.assertRaises(local.Git.Exception):
+ self.assertEqual(dict(), local.Git(self.path).info())
- with mocks.local.Git(dirname, git_svn=True, remote='g...@example.org:{}'.format(self.path)), MockTime:
- self.assertDictEqual(
- {
- 'Path': '.',
- 'Repository Root': 'g...@example.org:/mock/repository',
- 'URL': 'g...@example.org:/mock/repository/main',
- 'Revision': '9',
- 'Node Kind': 'directory',
- 'Schedule': 'normal',
- 'Last Changed Author': 'jbed...@apple.com',
- 'Last Changed Rev': '9',
- 'Last Changed Date': datetime.fromtimestamp(1601668000).strftime('%Y-%m-%d %H:%M:%S'),
- }, local.Git(dirname).info(),
- )
- finally:
- shutil.rmtree(dirname)
+ with mocks.local.Git(self.path, git_svn=True, remote='g...@example.org:mock/repository'), MockTime:
+ self.assertDictEqual(
+ {
+ 'Path': '.',
+ 'Repository Root': 'g...@example.org:mock/repository',
+ 'URL': 'g...@example.org:mock/repository/main',
+ 'Revision': '9',
+ 'Node Kind': 'directory',
+ 'Schedule': 'normal',
+ 'Last Changed Author': 'jbed...@apple.com',
+ 'Last Changed Rev': '9',
+ 'Last Changed Date': datetime.fromtimestamp(1601668000).strftime('%Y-%m-%d %H:%M:%S'),
+ }, local.Git(self.path).info(),
+ )
def test_commit_revision(self):
- try:
- dirname = tempfile.mkdtemp()
- with mocks.local.Git(dirname), MockTime, LoggerCapture():
- with self.assertRaises(local.Git.Exception):
- self.assertEqual(None, local.Git(dirname).commit(revision=1))
+ with mocks.local.Git(self.path), MockTime, LoggerCapture():
+ with self.assertRaises(local.Git.Exception):
+ self.assertEqual(None, local.Git(self.path).commit(revision=1))
- with mocks.local.Git(dirname, git_svn=True, remote='g...@example.org:{}'.format(self.path)), MockTime, LoggerCapture():
- self.assertEqual('1@main', str(local.Git(dirname).commit(revision=1)))
- self.assertEqual('2@main', str(local.Git(dirname).commit(revision=2)))
- self.assertEqual('2.1@branch-a', str(local.Git(dirname).commit(revision=3)))
- self.assertEqual('3@main', str(local.Git(dirname).commit(revision=4)))
- self.assertEqual('2.2@branch-b', str(local.Git(dirname).commit(revision=5)))
- self.assertEqual('2.2@branch-a', str(local.Git(dirname).commit(revision=6)))
- self.assertEqual('2.3@branch-b', str(local.Git(dirname).commit(revision=7)))
- self.assertEqual('4@main', str(local.Git(dirname).commit(revision=8)))
+ with mocks.local.Git(self.path, git_svn=True, remote='g...@example.org:{}'.format(self.path)), MockTime, LoggerCapture():
+ self.assertEqual('1@main', str(local.Git(self.path).commit(revision=1)))
+ self.assertEqual('2@main', str(local.Git(self.path).commit(revision=2)))
+ self.assertEqual('2.1@branch-a', str(local.Git(self.path).commit(revision=3)))
+ self.assertEqual('3@main', str(local.Git(self.path).commit(revision=4)))
+ self.assertEqual('2.2@branch-b', str(local.Git(self.path).commit(revision=5)))
+ self.assertEqual('2.2@branch-a', str(local.Git(self.path).commit(revision=6)))
+ self.assertEqual('2.3@branch-b', str(local.Git(self.path).commit(revision=7)))
+ self.assertEqual('4@main', str(local.Git(self.path).commit(revision=8)))
- # Out-of-bounds commit
- with self.assertRaises(local.Git.Exception):
- self.assertEqual(None, local.Git(dirname).commit(revision=10))
- finally:
- shutil.rmtree(dirname)
+ # Out-of-bounds commit
+ with self.assertRaises(local.Git.Exception):
+ self.assertEqual(None, local.Git(self.path).commit(revision=10))
def test_commit_hash(self):
for mock in [mocks.local.Git(self.path), mocks.local.Git(self.path, git_svn=True)]:
@@ -285,7 +273,7 @@
def test_commits(self):
for mock in [mocks.local.Git(self.path), mocks.local.Git(self.path, git_svn=True)]:
- with mock:
+ with mock, LoggerCapture():
git = local.Git(self.path)
self.assertEqual(Commit.Encoder().default([
git.commit(hash='bae5d1e9'),
@@ -296,7 +284,7 @@
def test_commits_branch(self):
for mock in [mocks.local.Git(self.path), mocks.local.Git(self.path, git_svn=True)]:
- with mock:
+ with mock, LoggerCapture():
git = local.Git(self.path)
self.assertEqual(Commit.Encoder().default([
git.commit(hash='621652ad'),
@@ -378,7 +366,7 @@
)
-class TestGitHub(unittest.TestCase):
+class TestGitHub(testing.TestCase):
remote = 'https://github.example.com/WebKit/WebKit'
def test_detection(self):
@@ -530,8 +518,7 @@
]), Commit.Encoder().default(list(git.commits(begin=dict(argument='9b8311f2'), end=dict(argument='621652ad')))))
-
-class TestBitBucket(unittest.TestCase):
+class TestBitBucket(testing.TestCase):
remote = 'https://bitbucket.example.com/projects/WEBKIT/repos/webkit'
def test_detection(self):
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/scm_unittest.py (279346 => 279347)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/scm_unittest.py 2021-06-28 19:56:01 UTC (rev 279346)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/scm_unittest.py 2021-06-28 19:57:15 UTC (rev 279347)
@@ -20,14 +20,20 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+import os
-import unittest
+from webkitcorepy import testing
from webkitscmpy import local, mocks
-class TestScm(unittest.TestCase):
- path = '/mock/directory'
+class TestScm(testing.PathTestCase):
+ basepath = 'mock/repository'
+ def setUp(self):
+ super(TestScm, self).setUp()
+ os.mkdir(os.path.join(self.path, '.git'))
+ os.mkdir(os.path.join(self.path, '.svn'))
+
def test_detection(self):
with mocks.local.Git(), mocks.local.Svn():
with self.assertRaises(OSError):
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py (279346 => 279347)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py 2021-06-28 19:56:01 UTC (rev 279346)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_git_svn_unittest.py 2021-06-28 19:57:15 UTC (rev 279347)
@@ -21,123 +21,110 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
-import shutil
-import tempfile
-import unittest
-from datetime import datetime
-from webkitcorepy import LoggerCapture, OutputCapture
+from webkitcorepy import OutputCapture, testing
from webkitcorepy.mocks import Time as MockTime
from webkitscmpy import program, mocks
-class TestSetupGitSvn(unittest.TestCase):
+class TestSetupGitSvn(testing.PathTestCase):
git_remote = 'g...@example.org:Example'
svn_remote = 'https://svn.example.org/repository/example'
+ basepath = 'mock/repository'
+ def setUp(self):
+ super(TestSetupGitSvn, self).setUp()
+ os.mkdir(os.path.join(self.path, '.git'))
+ os.mkdir(os.path.join(self.path, '.svn'))
+
def test_svn(self):
- try:
- dirname = tempfile.mkdtemp()
- with OutputCapture() as captured, mocks.local.Git(), mocks.local.Svn(dirname, remote=self.svn_remote), MockTime:
- self.assertEqual(1, program.main(
- args=('setup-git-svn',),
- path=dirname,
- subversion=self.svn_remote,
- ))
- self.assertEqual(captured.stderr.getvalue(), 'Cannot setup git-svn on Subversion repository\n')
+ with OutputCapture() as captured, mocks.local.Git(), mocks.local.Svn(self.path, remote=self.svn_remote), MockTime:
+ self.assertEqual(1, program.main(
+ args=('setup-git-svn',),
+ path=self.path,
+ subversion=self.svn_remote,
+ ))
+ self.assertEqual(captured.stderr.getvalue(), 'Cannot setup git-svn on Subversion repository\n')
- finally:
- shutil.rmtree(dirname)
+ def test_empty(self):
+ with OutputCapture() as captured, mocks.local.Git(self.path, remote=self.git_remote), mocks.local.Svn(), mocks.remote.Svn(remote=self.svn_remote.split('://')[1]), MockTime:
+ self.assertEqual(0, program.main(
+ args=('setup-git-svn',),
+ path=self.path,
+ subversion=self.svn_remote,
+ ))
+ self.assertEqual(
+ captured.stdout.getvalue(),
+ 'Adding svn-remote to git config\n' +
+ 'Populating svn commit mapping (will take a few minutes)...\n',
+ )
- def test_empty(self):
- try:
- dirname = tempfile.mkdtemp()
- with OutputCapture() as captured, mocks.local.Git(dirname, remote=self.git_remote), mocks.local.Svn(), mocks.remote.Svn(remote=self.svn_remote.split('://')[1]), MockTime:
- self.assertEqual(0, program.main(
- args=('setup-git-svn',),
- path=dirname,
- subversion=self.svn_remote,
- ))
+ with open(os.path.join(self.path, '.git/config')) as config:
self.assertEqual(
- captured.stdout.getvalue(),
- 'Adding svn-remote to git config\n' +
- 'Populating svn commit mapping (will take a few minutes)...\n',
+ config.read(),
+ '[core]\n'
+ '\trepositoryformatversion = 0\n'
+ '\tfilemode = true\n'
+ '\tbare = false\n'
+ '\tlogallrefupdates = true\n'
+ '\tignorecase = true\n'
+ '\tprecomposeunicode = true\n'
+ '[remote "origin"]\n'
+ '\turl = {git_remote}\n'
+ '\tfetch = +refs/heads/*:refs/remotes/origin/*\n'
+ '[branch "main"]\n'
+ '\tremote = origin\n'
+ '\tmerge = refs/heads/main\n'
+ '[svn-remote "svn"]\n'
+ '\turl = {svn_remote}\n'
+ '\tfetch = trunk:refs/remotes/origin/main\n'.format(
+ git_remote=self.git_remote,
+ svn_remote=self.svn_remote,
+ ),
)
- with open(os.path.join(dirname, '.git/config')) as config:
- self.assertEqual(
- config.read(),
- '[core]\n'
- '\trepositoryformatversion = 0\n'
- '\tfilemode = true\n'
- '\tbare = false\n'
- '\tlogallrefupdates = true\n'
- '\tignorecase = true\n'
- '\tprecomposeunicode = true\n'
- '[remote "origin"]\n'
- '\turl = {git_remote}\n'
- '\tfetch = +refs/heads/*:refs/remotes/origin/*\n'
- '[branch "main"]\n'
- '\tremote = origin\n'
- '\tmerge = refs/heads/main\n'
- '[svn-remote "svn"]\n'
- '\turl = {svn_remote}\n'
- '\tfetch = trunk:refs/remotes/origin/main\n'.format(
- git_remote=self.git_remote,
- svn_remote=self.svn_remote,
- ),
- )
+ def test_add(self):
+ with OutputCapture(), mocks.local.Git(self.path, remote=self.git_remote), mocks.local.Svn(), mocks.remote.Svn(remote=self.svn_remote.split('://')[1]), MockTime:
+ self.assertEqual(0, program.main(
+ args=('setup-git-svn',),
+ path=self.path,
+ subversion=self.svn_remote,
+ ))
- finally:
- shutil.rmtree(dirname)
+ with OutputCapture() as captured, mocks.local.Git(self.path, remote=self.git_remote), mocks.local.Svn(), mocks.remote.Svn(remote=self.svn_remote.split('://')[1]), MockTime:
+ self.assertEqual(0, program.main(
+ args=('setup-git-svn', '--all-branches'),
+ path=self.path,
+ subversion=self.svn_remote,
+ ))
+ self.assertEqual(
+ captured.stdout.getvalue(),
+ 'Adding svn-remote to git config\n' +
+ 'Populating svn commit mapping (will take a few minutes)...\n',
+ )
- def test_add(self):
- try:
- dirname = tempfile.mkdtemp()
- with OutputCapture(), mocks.local.Git(dirname, remote=self.git_remote), mocks.local.Svn(), mocks.remote.Svn(remote=self.svn_remote.split('://')[1]), MockTime:
- self.assertEqual(0, program.main(
- args=('setup-git-svn',),
- path=dirname,
- subversion=self.svn_remote,
- ))
-
- with OutputCapture() as captured, mocks.local.Git(dirname, remote=self.git_remote), mocks.local.Svn(), mocks.remote.Svn(remote=self.svn_remote.split('://')[1]), MockTime:
- self.assertEqual(0, program.main(
- args=('setup-git-svn', '--all-branches'),
- path=dirname,
- subversion=self.svn_remote,
- ))
+ with open(os.path.join(self.path, '.git/config')) as config:
self.assertEqual(
- captured.stdout.getvalue(),
- 'Adding svn-remote to git config\n' +
- 'Populating svn commit mapping (will take a few minutes)...\n',
+ config.read(),
+ '[core]\n'
+ '\trepositoryformatversion = 0\n'
+ '\tfilemode = true\n'
+ '\tbare = false\n'
+ '\tlogallrefupdates = true\n'
+ '\tignorecase = true\n'
+ '\tprecomposeunicode = true\n'
+ '[remote "origin"]\n'
+ '\turl = {git_remote}\n'
+ '\tfetch = +refs/heads/*:refs/remotes/origin/*\n'
+ '[branch "main"]\n'
+ '\tremote = origin\n'
+ '\tmerge = refs/heads/main\n'
+ '[svn-remote "svn"]\n'
+ '\turl = {svn_remote}\n'
+ '\tfetch = trunk:refs/remotes/origin/main\n'
+ '\tfetch = branches/branch-a:refs/remotes/origin/branch-a\n'
+ '\tfetch = branches/branch-b:refs/remotes/origin/branch-b\n'.format(
+ git_remote=self.git_remote,
+ svn_remote=self.svn_remote,
+ ),
)
-
- with open(os.path.join(dirname, '.git/config')) as config:
- self.assertEqual(
- config.read(),
- '[core]\n'
- '\trepositoryformatversion = 0\n'
- '\tfilemode = true\n'
- '\tbare = false\n'
- '\tlogallrefupdates = true\n'
- '\tignorecase = true\n'
- '\tprecomposeunicode = true\n'
- '[remote "origin"]\n'
- '\turl = {git_remote}\n'
- '\tfetch = +refs/heads/*:refs/remotes/origin/*\n'
- '[branch "main"]\n'
- '\tremote = origin\n'
- '\tmerge = refs/heads/main\n'
- '[svn-remote "svn"]\n'
- '\turl = {svn_remote}\n'
- '\tfetch = trunk:refs/remotes/origin/main\n'
- '\tfetch = branches/branch-a:refs/remotes/origin/branch-a\n'
- '\tfetch = branches/branch-b:refs/remotes/origin/branch-b\n'.format(
- git_remote=self.git_remote,
- svn_remote=self.svn_remote,
- ),
- )
-
- finally:
- shutil.rmtree(dirname)
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py (279346 => 279347)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py 2021-06-28 19:56:01 UTC (rev 279346)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py 2021-06-28 19:57:15 UTC (rev 279347)
@@ -21,18 +21,19 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
-import shutil
-import tempfile
-import unittest
from datetime import datetime, timedelta
-from webkitcorepy import OutputCapture
+from webkitcorepy import OutputCapture, LoggerCapture, testing
from webkitscmpy import Commit, local, mocks, remote
-class TestLocalSvn(unittest.TestCase):
- path = '/mock/repository'
+class TestLocalSvn(testing.PathTestCase):
+ basepath = 'mock/repository'
+ def setUp(self):
+ super(TestLocalSvn, self).setUp()
+ os.mkdir(os.path.join(self.path, '.svn'))
+
def test_detection(self):
with mocks.local.Svn(self.path), mocks.local.Git():
detect = local.Scm.from_path(self.path)
@@ -81,7 +82,7 @@
self.assertDictEqual(
{
u'Path': u'.',
- u'Working Copy Root Path': u'/mock/repository',
+ u'Working Copy Root Path': self.path,
u'Repository Root': u'https://svn.mock.org/repository/repository',
u'URL': u'https://svn.mock.org/repository/repository/trunk',
u'Relative URL': u'^/trunk',
@@ -95,7 +96,7 @@
)
def test_commit_revision(self):
- with mocks.local.Svn(self.path), OutputCapture():
+ with mocks.local.Svn(self.path), LoggerCapture():
self.assertEqual('1@trunk', str(local.Svn(self.path).commit(revision=1)))
self.assertEqual('2@trunk', str(local.Svn(self.path).commit(revision=2)))
self.assertEqual('2.1@branch-a', str(local.Svn(self.path).commit(revision=3)))
@@ -110,13 +111,13 @@
self.assertEqual(None, local.Svn(self.path).commit(revision=11))
def test_commit_from_branch(self):
- with mocks.local.Svn(self.path), OutputCapture():
+ with mocks.local.Svn(self.path), LoggerCapture():
self.assertEqual('4@trunk', str(local.Svn(self.path).commit(branch='trunk')))
self.assertEqual('2.2@branch-a', str(local.Svn(self.path).commit(branch='branch-a')))
self.assertEqual('2.3@branch-b', str(local.Svn(self.path).commit(branch='branch-b')))
def test_identifier(self):
- with mocks.local.Svn(self.path), OutputCapture():
+ with mocks.local.Svn(self.path), LoggerCapture():
self.assertEqual(1, local.Svn(self.path).commit(identifier='1@trunk').revision)
self.assertEqual(2, local.Svn(self.path).commit(identifier='2@trunk').revision)
self.assertEqual(3, local.Svn(self.path).commit(identifier='2.1@branch-a').revision)
@@ -127,7 +128,7 @@
self.assertEqual(8, local.Svn(self.path).commit(identifier='2.3@branch-b').revision)
def test_non_cannonical_identifiers(self):
- with mocks.local.Svn(self.path), OutputCapture():
+ with mocks.local.Svn(self.path), LoggerCapture():
self.assertEqual('2@trunk', str(local.Svn(self.path).commit(identifier='0@branch-a')))
self.assertEqual('1@trunk', str(local.Svn(self.path).commit(identifier='-1@branch-a')))
@@ -181,31 +182,26 @@
self.assertEqual('2.1@branch-a', str(repo.commit(revision=3)))
def test_cache(self):
- try:
- dirname = tempfile.mkdtemp()
- with mocks.local.Svn(dirname) as mock_repo, OutputCapture():
- os.mkdir(os.path.join(dirname, '.svn'))
- self.assertEqual('4@trunk', str(local.Svn(dirname).commit()))
+ with mocks.local.Svn(self.path) as mock_repo, OutputCapture():
+ self.assertEqual('4@trunk', str(local.Svn(self.path).commit()))
- mock_repo.connected = False
- commit = local.Svn(dirname).commit()
- self.assertEqual('4@trunk', str(commit))
+ mock_repo.connected = False
+ commit = local.Svn(self.path).commit()
+ self.assertEqual('4@trunk', str(commit))
- with self.assertRaises(local.Svn.Exception):
- local.Svn(dirname).commit(revision=3)
- finally:
- shutil.rmtree(dirname)
+ with self.assertRaises(local.Svn.Exception):
+ local.Svn(self.path).commit(revision=3)
def test_tag(self):
- with mocks.local.Svn(self.path), OutputCapture():
+ with mocks.local.Svn(self.path), LoggerCapture():
self.assertEqual(9, local.Svn(self.path).commit(tag='tag-1').revision)
def test_tag_previous(self):
- with mocks.local.Svn(self.path), OutputCapture():
+ with mocks.local.Svn(self.path), LoggerCapture():
self.assertEqual(7, local.Svn(self.path).commit(identifier='2.2@tags/tag-1').revision)
def test_checkout(self):
- with mocks.local.Svn(self.path), OutputCapture():
+ with mocks.local.Svn(self.path), LoggerCapture():
repository = local.Svn(self.path)
self.assertEqual(6, repository.commit().revision)
@@ -219,20 +215,20 @@
self.assertEqual(9, repository.commit().revision)
def test_no_log(self):
- with mocks.local.Svn(self.path), OutputCapture():
+ with mocks.local.Svn(self.path), LoggerCapture():
self.assertIsNone(local.Svn(self.path).commit(identifier='4@trunk', include_log=False).message)
def test_alternative_default_branch(self):
- with mocks.local.Svn(self.path), OutputCapture():
+ with mocks.local.Svn(self.path), LoggerCapture():
self.assertEqual(str(local.Svn(self.path).find('4@main')), '4@trunk')
self.assertEqual(str(local.Svn(self.path).find('4@master')), '4@trunk')
def test_no_identifier(self):
- with mocks.local.Svn(self.path), OutputCapture():
+ with mocks.local.Svn(self.path), LoggerCapture():
self.assertIsNone(local.Svn(self.path).find('trunk', include_identifier=False).identifier)
def test_commits(self):
- with mocks.local.Svn(self.path), OutputCapture():
+ with mocks.local.Svn(self.path), LoggerCapture():
svn = local.Svn(self.path)
self.assertEqual(Commit.Encoder().default([
svn.commit(revision='r6'),
@@ -242,7 +238,7 @@
]), Commit.Encoder().default(list(svn.commits(begin=dict(revision='r1'), end=dict(revision='r6')))))
def test_commits_branch(self):
- with mocks.local.Svn(self.path), OutputCapture():
+ with mocks.local.Svn(self.path), LoggerCapture():
svn = local.Svn(self.path)
self.assertEqual(Commit.Encoder().default([
svn.commit(revision='r7'),
@@ -252,7 +248,7 @@
]), Commit.Encoder().default(list(svn.commits(begin=dict(argument='r1'), end=dict(argument='r7')))))
-class TestRemoteSvn(unittest.TestCase):
+class TestRemoteSvn(testing.TestCase):
remote = 'https://svn.example.org/repository/webkit'
def test_detection(self):