Skip to content

Commit

Permalink
Add fixture for assertDictContainsSubset.
Browse files Browse the repository at this point in the history
Thanks to Ryan T. Dean for providing the idea.
Closes #22.
  • Loading branch information
htgoebel committed Aug 16, 2017
1 parent 2312deb commit 44ea691
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
21 changes: 21 additions & 0 deletions tests/fixtures/self_assert/assertDictContainsSubset_in.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# required-method: assertDictContainsSubset

class TestDictEqual(TestCase):
def test_simple(self):
self.assertDictContainsSubset({'a: 1'}, superset)

def test_simple_msg(self):
self.assertDictContainsSubset(subset, {'a: 1'}, msg="This is wrong!")

def test_simple_msg2(self):
self.assertDictContainsSubset(subset, {'a: 1'}, "This is wrong!")

def test_line_wrapping(self):
self.assertDictContainsSubset(
{'b': 2},
{
'a': 1,
'b': 2,
},
"This is wrong!",
)
21 changes: 21 additions & 0 deletions tests/fixtures/self_assert/assertDictContainsSubset_out.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# required-method: assertDictContainsSubset

class TestDictEqual(TestCase):
def test_simple(self):
assert dict({'a: 1'}, **superset) == superset

This comment has been minimized.

Copy link
@RonnyPfannschmidt

RonnyPfannschmidt Aug 16, 2017

Member

this code needs to read dict(superset, **{'a: 1'}) == superset)


def test_simple_msg(self):
assert dict(subset, **{'a: 1'}) == {'a: 1'}, "This is wrong!"

This comment has been minimized.

Copy link
@RonnyPfannschmidt

RonnyPfannschmidt Aug 16, 2017

Member

all the others are reversed as well


def test_simple_msg2(self):
assert dict(subset, **{'a: 1'}) == {'a: 1'}, "This is wrong!"

def test_line_wrapping(self):
assert dict({'b': 2}, **{
'a': 1,
'b': 2,
}) == {
'a': 1,
'b': 2,
}, \
"This is wrong!"
4 changes: 2 additions & 2 deletions unittest2pytest/fixes/fix_self_assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def fill_template(template, *args):
p.prefix = ''
else:
p = Name(p)
kids.append(p)
kids.append(p.clone())
return kids

def DualOp(template, first, second, kws):
Expand Down Expand Up @@ -273,8 +273,8 @@ def get_import_nodes(node):
'assertTupleEqual': partial(CompOp, '=='),
'assertSequenceEqual': SequenceEqual,

'assertDictContainsSubset': partial(DualOp, 'dict(\1, **\2) == \2'),

This comment has been minimized.

Copy link
@RonnyPfannschmidt

RonnyPfannschmidt Aug 16, 2017

Member

my understanding is that this one should be dict(\2, **\1) == \2)

given the first parameter is the subset, and the second parameter is the subset

the test is for the superset being merged with the new subset being equal to the old superset

This comment has been minimized.

Copy link
@htgoebel

htgoebel Aug 16, 2017

Author Collaborator

Oh, thanks for pointing to this. I implemented it the wrong way round by accident.

This comment has been minimized.

Copy link
@htgoebel

htgoebel Aug 16, 2017

Author Collaborator

Fixed in 758fa33.

# :todo:
#'assertDictContainsSubset': '',
#'assertItemsEqual': '', # unordered sequence specific comparison.

'assertAlmostEqual': partial(AlmostOp, "==", "<"),
Expand Down

0 comments on commit 44ea691

Please sign in to comment.