From ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1 Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Sat, 11 Mar 2023 06:46:20 +0000 Subject: Format codebase with black and check formatting in CQ Apply rules set by https://gerrit-review.googlesource.com/c/git-repo/+/362954/ across the codebase and fix any lingering errors caught by flake8. Also check black formatting in run_tests (and CQ). Bug: b/267675342 Change-Id: I972d77649dac351150dcfeb1cd1ad0ea2efc1956 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/363474 Reviewed-by: Mike Frysinger Tested-by: Gavin Mak Commit-Queue: Gavin Mak --- tests/test_ssh.py | 90 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 43 deletions(-) (limited to 'tests/test_ssh.py') diff --git a/tests/test_ssh.py b/tests/test_ssh.py index ffb5cb94..a9c1be7f 100644 --- a/tests/test_ssh.py +++ b/tests/test_ssh.py @@ -23,52 +23,56 @@ import ssh class SshTests(unittest.TestCase): - """Tests the ssh functions.""" + """Tests the ssh functions.""" - def test_parse_ssh_version(self): - """Check _parse_ssh_version() handling.""" - ver = ssh._parse_ssh_version('Unknown\n') - self.assertEqual(ver, ()) - ver = ssh._parse_ssh_version('OpenSSH_1.0\n') - self.assertEqual(ver, (1, 0)) - ver = ssh._parse_ssh_version('OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.13, OpenSSL 1.0.1f 6 Jan 2014\n') - self.assertEqual(ver, (6, 6, 1)) - ver = ssh._parse_ssh_version('OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017\n') - self.assertEqual(ver, (7, 6)) + def test_parse_ssh_version(self): + """Check _parse_ssh_version() handling.""" + ver = ssh._parse_ssh_version("Unknown\n") + self.assertEqual(ver, ()) + ver = ssh._parse_ssh_version("OpenSSH_1.0\n") + self.assertEqual(ver, (1, 0)) + ver = ssh._parse_ssh_version( + "OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.13, OpenSSL 1.0.1f 6 Jan 2014\n" + ) + self.assertEqual(ver, (6, 6, 1)) + ver = ssh._parse_ssh_version( + "OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017\n" + ) + self.assertEqual(ver, (7, 6)) - def test_version(self): - """Check version() handling.""" - with mock.patch('ssh._run_ssh_version', return_value='OpenSSH_1.2\n'): - self.assertEqual(ssh.version(), (1, 2)) + def test_version(self): + """Check version() handling.""" + with mock.patch("ssh._run_ssh_version", return_value="OpenSSH_1.2\n"): + self.assertEqual(ssh.version(), (1, 2)) - def test_context_manager_empty(self): - """Verify context manager with no clients works correctly.""" - with multiprocessing.Manager() as manager: - with ssh.ProxyManager(manager): - pass + def test_context_manager_empty(self): + """Verify context manager with no clients works correctly.""" + with multiprocessing.Manager() as manager: + with ssh.ProxyManager(manager): + pass - def test_context_manager_child_cleanup(self): - """Verify orphaned clients & masters get cleaned up.""" - with multiprocessing.Manager() as manager: - with ssh.ProxyManager(manager) as ssh_proxy: - client = subprocess.Popen(['sleep', '964853320']) - ssh_proxy.add_client(client) - master = subprocess.Popen(['sleep', '964853321']) - ssh_proxy.add_master(master) - # If the process still exists, these will throw timeout errors. - client.wait(0) - master.wait(0) + def test_context_manager_child_cleanup(self): + """Verify orphaned clients & masters get cleaned up.""" + with multiprocessing.Manager() as manager: + with ssh.ProxyManager(manager) as ssh_proxy: + client = subprocess.Popen(["sleep", "964853320"]) + ssh_proxy.add_client(client) + master = subprocess.Popen(["sleep", "964853321"]) + ssh_proxy.add_master(master) + # If the process still exists, these will throw timeout errors. + client.wait(0) + master.wait(0) - def test_ssh_sock(self): - """Check sock() function.""" - manager = multiprocessing.Manager() - proxy = ssh.ProxyManager(manager) - with mock.patch('tempfile.mkdtemp', return_value='/tmp/foo'): - # old ssh version uses port - with mock.patch('ssh.version', return_value=(6, 6)): - self.assertTrue(proxy.sock().endswith('%p')) + def test_ssh_sock(self): + """Check sock() function.""" + manager = multiprocessing.Manager() + proxy = ssh.ProxyManager(manager) + with mock.patch("tempfile.mkdtemp", return_value="/tmp/foo"): + # Old ssh version uses port. + with mock.patch("ssh.version", return_value=(6, 6)): + self.assertTrue(proxy.sock().endswith("%p")) - proxy._sock_path = None - # new ssh version uses hash - with mock.patch('ssh.version', return_value=(6, 7)): - self.assertTrue(proxy.sock().endswith('%C')) + proxy._sock_path = None + # New ssh version uses hash. + with mock.patch("ssh.version", return_value=(6, 7)): + self.assertTrue(proxy.sock().endswith("%C")) -- cgit v1.2.3-54-g00ecf