From f766fe0a87a1a4de5323dd5b81e51448b53d3329 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Fri, 12 May 2017 09:10:43 -0700 Subject: [PATCH] Update Hg integration tests to use assert_status(). Summary: `HgExtensionTestBase.assert_status()` was added in D4814422, but it was only applied to `update_test.py`. This change updates the docstring (it appears to have been copy/pasted from a nearby method), and makes use of it in the other integration tests. Reviewed By: wez Differential Revision: D5050775 fbshipit-source-id: bb70740b6f455a84e7a22c3286c8ddbe2462f816 --- eden/integration/hg/add_test.py | 36 ++++++++++++++----- .../hg/lib/hg_extension_test_base.py | 7 +++- eden/integration/hg/status_test.py | 27 +++++++------- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/eden/integration/hg/add_test.py b/eden/integration/hg/add_test.py index ab69dc71ca..c71de40830 100644 --- a/eden/integration/hg/add_test.py +++ b/eden/integration/hg/add_test.py @@ -21,37 +21,55 @@ class AddTest(HgExtensionTestBase): self.touch('dir1/b.txt') self.mkdir('dir2') self.touch('dir2/c.txt') - self.assertEqual('? dir1/b.txt\n? dir2/c.txt\n', self.status()) + self.assert_status({ + 'dir1/b.txt': '?', + 'dir2/c.txt': '?', + }) # `hg add dir2` should ensure only things under dir2 are added. self.hg('add', 'dir2') - self.assertEqual('A dir2/c.txt\n? dir1/b.txt\n', self.status()) + self.assert_status({ + 'dir1/b.txt': '?', + 'dir2/c.txt': 'A', + }) # This is the equivalent of `hg forget dir1/a.txt`. self.hg('rm', '--force', 'dir1/a.txt') self.write_file('dir1/a.txt', 'original contents') self.touch('dir1/a.txt') - self.assertEqual('A dir2/c.txt\nR dir1/a.txt\n? dir1/b.txt\n', - self.status()) + self.assert_status({ + 'dir1/a.txt': 'R', + 'dir1/b.txt': '?', + 'dir2/c.txt': 'A', + }) # Running `hg add .` should remove the removal marker from dir1/a.txt # because dir1/a.txt is still on disk. self.hg('add') - self.assertEqual('A dir1/b.txt\nA dir2/c.txt\n', self.status()) + self.assert_status({ + 'dir1/b.txt': 'A', + 'dir2/c.txt': 'A', + }) self.hg('rm', 'dir1/a.txt') self.write_file('dir1/a.txt', 'different contents') # Running `hg add dir1` should remove the removal marker from # dir1/a.txt, but `hg status` should also reflect that it is modified. self.hg('add', 'dir1') - self.assertEqual('M dir1/a.txt\nA dir1/b.txt\nA dir2/c.txt\n', - self.status()) + self.assert_status({ + 'dir1/a.txt': 'M', + 'dir1/b.txt': 'A', + 'dir2/c.txt': 'A', + }) self.hg('rm', '--force', 'dir1/a.txt') # This should not add dir1/a.txt back because it is not on disk. self.hg('add', 'dir1') - self.assertEqual('A dir1/b.txt\nA dir2/c.txt\nR dir1/a.txt\n', - self.status()) + self.assert_status({ + 'dir1/a.txt': 'R', + 'dir1/b.txt': 'A', + 'dir2/c.txt': 'A', + }) with self.assertRaises(subprocess.CalledProcessError) as context: self.hg('add', 'dir3') diff --git a/eden/integration/hg/lib/hg_extension_test_base.py b/eden/integration/hg/lib/hg_extension_test_base.py index 7b8538e795..857109872f 100644 --- a/eden/integration/hg/lib/hg_extension_test_base.py +++ b/eden/integration/hg/lib/hg_extension_test_base.py @@ -121,7 +121,12 @@ class HgExtensionTestBase(testcase.EdenTestCase): return self.repo.status() def assert_status(self, expected, msg=None, check_ignored=True): - '''Returns the output of `hg status` as a string.''' + '''Asserts the output of `hg status`. `expected` is a dict where keys + are paths relative to the repo root and values are the single-character + string that represents the status: 'M', 'A', 'R', '!', '?', 'I'. + + 'C' is not currently supported. + ''' args = ['status', '--print0'] if check_ignored: args.append('-mardui') diff --git a/eden/integration/hg/status_test.py b/eden/integration/hg/status_test.py index e78df5db78..b8187edb1b 100644 --- a/eden/integration/hg/status_test.py +++ b/eden/integration/hg/status_test.py @@ -17,26 +17,29 @@ class StatusTest(HgExtensionTestBase): def test_status(self): '''Test various `hg status` states in the root of an Eden mount.''' - empty_status = self.status() - self.assertEqual('', empty_status) + self.assert_status_empty() self.touch('world.txt') - untracked_status = self.status() - self.assertEqual('? world.txt\n', untracked_status) + self.assert_status({'world.txt': '?'}) self.hg('add', 'world.txt') - added_status = self.status() - self.assertEqual('A world.txt\n', added_status) + self.assert_status({'world.txt': 'A'}) self.rm('hello.txt') - missing_status = self.status() - self.assertEqual('A world.txt\n! hello.txt\n', missing_status) + self.assert_status({ + 'hello.txt': '!', + 'world.txt': 'A', + }) with open(self.get_path('hello.txt'), 'w') as f: f.write('new contents') - modified_status = self.status() - self.assertEqual('M hello.txt\nA world.txt\n', modified_status) + self.assert_status({ + 'hello.txt': 'M', + 'world.txt': 'A', + }) self.hg('rm', '--force', 'hello.txt') - removed_status = self.status() - self.assertEqual('A world.txt\nR hello.txt\n', removed_status) + self.assert_status({ + 'hello.txt': 'R', + 'world.txt': 'A', + })