From 39cdfaafd14104c0283a63530467952d6e9e8772 Mon Sep 17 00:00:00 2001 From: Keerthan Jaic Date: Tue, 1 Oct 2019 13:02:11 +0100 Subject: [PATCH] Add support for assertItemsEqual --- tests/fixtures/self_assert/assertItemsEqual_in.py | 11 +++++++++++ tests/fixtures/self_assert/assertItemsEqual_out.py | 11 +++++++++++ unittest2pytest/fixes/fix_self_assert.py | 3 +-- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/self_assert/assertItemsEqual_in.py create mode 100644 tests/fixtures/self_assert/assertItemsEqual_out.py diff --git a/tests/fixtures/self_assert/assertItemsEqual_in.py b/tests/fixtures/self_assert/assertItemsEqual_in.py new file mode 100644 index 0000000..c486d6d --- /dev/null +++ b/tests/fixtures/self_assert/assertItemsEqual_in.py @@ -0,0 +1,11 @@ +# required-method: assertItemsEqual + +class TestItemsEqual(TestCase): + def test_simple(self): + self.assertItemsEqual(a, b) + + def test_simple_msg(self): + self.assertItemsEqual(a, b, msg="This is wrong!") + + def test_simple_msg2(self): + self.assertItemsEqual(a, b, "This is wrong!") diff --git a/tests/fixtures/self_assert/assertItemsEqual_out.py b/tests/fixtures/self_assert/assertItemsEqual_out.py new file mode 100644 index 0000000..0f3ac5d --- /dev/null +++ b/tests/fixtures/self_assert/assertItemsEqual_out.py @@ -0,0 +1,11 @@ +# required-method: assertItemsEqual + +class TestItemsEqual(TestCase): + def test_simple(self): + assert sorted(a) == sorted(b) + + def test_simple_msg(self): + assert sorted(a) == sorted(b), "This is wrong!" + + def test_simple_msg2(self): + assert sorted(a) == sorted(b), "This is wrong!" diff --git a/unittest2pytest/fixes/fix_self_assert.py b/unittest2pytest/fixes/fix_self_assert.py index a2f9a03..8000c08 100644 --- a/unittest2pytest/fixes/fix_self_assert.py +++ b/unittest2pytest/fixes/fix_self_assert.py @@ -278,8 +278,7 @@ def get_import_nodes(node): 'assertSequenceEqual': SequenceEqual, 'assertDictContainsSubset': partial(DualOp, 'dict(\2, **\1) == \2'), - # :todo: - #'assertItemsEqual': '', # unordered sequence specific comparison. + 'assertItemsEqual': partial(DualOp, 'sorted(\1) == sorted(\2)'), 'assertAlmostEqual': partial(AlmostOp, "==", "<"), 'assertNotAlmostEqual': partial(AlmostOp, "!=", ">"),