Submitter | Siddharth Agarwal |
---|---|
Date | March 25, 2013, 12:27 a.m. |
Message ID | <7bc5b8e56c65d7ad228f.1364171269@sid0x220> |
Download | mbox | patch |
Permalink | /patch/1181/ |
State | Rejected |
Headers | show |
Comments
On Mon, Mar 25, 2013 at 2:27 AM, Siddharth Agarwal <sid0@fb.com> wrote: > > # HG changeset patch > # User Siddharth Agarwal <sid0@fb.com> > # Date 1364170255 25200 > # Sun Mar 24 17:10:55 2013 -0700 > # Node ID 7bc5b8e56c65d7ad228fe700974a9621bdfd42c4 > # Parent 78f178247f634bac6ff2ffe54b0d06185ef0e670 > dicthelpers: add unit tests You can write this as a standard Python unit test: http://selenic.com/repo/hg/file/a07be8953733/tests/test-atomictempfile.py
On 03/25/2013 03:38 AM, Idan Kamara wrote: > On Mon, Mar 25, 2013 at 2:27 AM, Siddharth Agarwal <sid0@fb.com > <mailto:sid0@fb.com>> wrote: > > > > # HG changeset patch > > # User Siddharth Agarwal <sid0@fb.com <mailto:sid0@fb.com>> > > # Date 1364170255 25200 > > # Sun Mar 24 17:10:55 2013 -0700 > > # Node ID 7bc5b8e56c65d7ad228fe700974a9621bdfd42c4 > > # Parent 78f178247f634bac6ff2ffe54b0d06185ef0e670 > > dicthelpers: add unit tests > > You can write this as a standard Python unit test: > http://selenic.com/repo/hg/file/a07be8953733/tests/test-atomictempfile.py > <https://urldefense.proofpoint.com/v1/url?u=http://selenic.com/repo/hg/file/a07be8953733/tests/test-atomictempfile.py&k=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=%2FSg8Zq7yFXBOhOzuAORckw%3D%3D%0A&m=Fn0Fj1tRMJlPS%2F1piNY0WvRx9uWByv8XVoYVUPgFOwY%3D%0A&s=d94f67d1c449109c6dbe2b65eec19ab5011820f603f5932be0f5241ba041683f> Aha, thanks.
Patch
diff --git a/tests/test-dicthelpers.py b/tests/test-dicthelpers.py new file mode 100644 --- /dev/null +++ b/tests/test-dicthelpers.py @@ -0,0 +1,34 @@ +from mercurial.dicthelpers import diff, join + +def test_dicthelpers(): + # empty dicts + print "diff({}, {}):", sorted(diff({}, {}).items()) + print "join({}, {}):", sorted(join({}, {}).items()) + + d1 = {} + d1['a'] = 'foo' + d1['b'] = 'bar' + d1['c'] = 'baz' + + # same identity + print "diff(d1, d1):", sorted(diff(d1, d1).items()) + print "join(d1, d1):", sorted(join(d1, d1).items()) + + # vs empty + print "diff(d1, {}):", sorted(diff(d1, {}).items()) + print "join(d1, {}):", sorted(join(d1, {}).items()) + + d2 = {} + d2['a'] = 'foo2' + d2['b'] = 'bar' + d2['d'] = 'quux' + + print "diff(d1, d2):", sorted(diff(d1, d2).items()) + print "join(d1, d2):", sorted(join(d1, d2).items()) + + # with default argument + print "diff(d1, d2, 123):", sorted(diff(d1, d2, 123).items()) + print "join(d1, d2, 456):", sorted(join(d1, d2, 456).items()) + +if __name__ == '__main__': + test_dicthelpers() diff --git a/tests/test-dicthelpers.py.out b/tests/test-dicthelpers.py.out new file mode 100644 --- /dev/null +++ b/tests/test-dicthelpers.py.out @@ -0,0 +1,10 @@ +diff({}, {}): [] +join({}, {}): [] +diff(d1, d1): [] +join(d1, d1): [('a', ('foo', 'foo')), ('b', ('bar', 'bar')), ('c', ('baz', 'baz'))] +diff(d1, {}): [('a', ('foo', None)), ('b', ('bar', None)), ('c', ('baz', None))] +join(d1, {}): [('a', ('foo', None)), ('b', ('bar', None)), ('c', ('baz', None))] +diff(d1, d2): [('a', ('foo', 'foo2')), ('c', ('baz', None)), ('d', (None, 'quux'))] +join(d1, d2): [('a', ('foo', 'foo2')), ('b', ('bar', 'bar')), ('c', ('baz', None)), ('d', (None, 'quux'))] +diff(d1, d2, 123): [('a', ('foo', 'foo2')), ('c', ('baz', 123)), ('d', (123, 'quux'))] +join(d1, d2, 456): [('a', ('foo', 'foo2')), ('b', ('bar', 'bar')), ('c', ('baz', 456)), ('d', (456, 'quux'))]