{"action":"created","comment":{"url":"https://api.github.com/repos/Simplistix/testfixtures/pulls/comments/42427706","id":42427706,"diff_hunk":"@@ -384,7 +419,45 @@ def compare(x, y, **kw):\n \n     raise AssertionError(message)\n \n-    \n+\n+def _get_expected_actual(x, y, expected, actual):\n+    \"\"\"\n+    Helper method for compare() to work out if it is being invoked with unnamed\n+    positional arguments x and y, or if expected/actual kwargs have been\n+    specified allowing us to provide more helpful error messages.\n+\n+    Returns a tuple (x, y, actual_expected) where actual_expected is a bool\n+    indicating if x and y are named the actual and expected values,\n+    respectively.\n+\n+    not_there is a singleton value used as the default for all four arguments\n+    to compare() to differentiate them from an explicitly passed None value.\n+\n+    Here are the possible inputs and corresponding outputs:\n+        (x=a, y=b, expected=not_there, actual=not_there) -> (a, b, False)\n+        (x=not_there, y=not_there, expected=a, actual=b) -> (a, b, True)\n+        (x=a, y=not_there, expected=a, actual=not_there) -> (b, a, True)\n+        (x=a, y=not_there, expected=not_there, actual=b) -> (a, b, True)\n+        Anything else -> ValueError\n+    \"\"\"\n+    count = sum((0 if x is not_there else 1 for x in (x, y, expected, actual)))\n+    if count != 2:\n+        raise ValueError('Exactly 2 of the arguments (x, y, expected, actual) '\n+                         'must be specified.')\n+\n+    if x is not_there and y is not not_there:\n+        raise ValueError('Must specify x and y together, '\n+                         'or x with one of expected/actual.')\n+\n+    if expected is not_there and actual is not_there:\n+        return x, y, False\n+    if x is not_there and y is not_there:\n+        return expected, actual, True\n+    if actual is not_there:\n+        return expected, x, True\n+    return x, actual, True","path":"testfixtures/comparison.py","position":222,"original_position":222,"commit_id":"509107a5d7e10c2994c525ac28bc82591e39ad36","original_commit_id":"509107a5d7e10c2994c525ac28bc82591e39ad36","user":{"login":"cjw296","id":632049,"avatar_url":"https://avatars.githubusercontent.com/u/632049?v=3","gravatar_id":"","url":"https://api.github.com/users/cjw296","html_url":"https://github.com/cjw296","followers_url":"https://api.github.com/users/cjw296/followers","following_url":"https://api.github.com/users/cjw296/following{/other_user}","gists_url":"https://api.github.com/users/cjw296/gists{/gist_id}","starred_url":"https://api.github.com/users/cjw296/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjw296/subscriptions","organizations_url":"https://api.github.com/users/cjw296/orgs","repos_url":"https://api.github.com/users/cjw296/repos","events_url":"https://api.github.com/users/cjw296/events{/privacy}","received_events_url":"https://api.github.com/users/cjw296/received_events","type":"User","site_admin":false},"body":"DEFINITELY not a fan of this huge extra method.\r\n\r\n\r\nI was envisaging more:\r\n\r\n```python\r\ndef compare(*args, **kwargs):\r\n    ...\r\n    if args:\r\n        x, y = args\r\n   else:\r\n        x = kwargs.pop('expected')\r\n        y = kwargs.pop('actual')\r\n```\r\n\r\nNot sure anything more fancy is required.\r\n\r\nDefinitely not keen to support anything other than `compare(a, b, ...)` or `compare(expected=a, actual=b)`.\r\n","created_at":"2015-10-19T21:22:43Z","updated_at":"2015-10-19T21:22:43Z","html_url":"https://github.com/Simplistix/testfixtures/pull/23#discussion_r42427706","pull_request_url":"https://api.github.com/repos/Simplistix/testfixtures/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/Simplistix/testfixtures/pulls/comments/42427706"},"html":{"href":"https://github.com/Simplistix/testfixtures/pull/23#discussion_r42427706"},"pull_request":{"href":"https://api.github.com/repos/Simplistix/testfixtures/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/Simplistix/testfixtures/pulls/23","id":48122468,"html_url":"https://github.com/Simplistix/testfixtures/pull/23","diff_url":"https://github.com/Simplistix/testfixtures/pull/23.diff","patch_url":"https://github.com/Simplistix/testfixtures/pull/23.patch","issue_url":"https://api.github.com/repos/Simplistix/testfixtures/issues/23","number":23,"state":"open","locked":false,"title":"Implementation of optional compare(expected=..., actual=...) params","user":{"login":"asqui","id":174182,"avatar_url":"https://avatars.githubusercontent.com/u/174182?v=3","gravatar_id":"","url":"https://api.github.com/users/asqui","html_url":"https://github.com/asqui","followers_url":"https://api.github.com/users/asqui/followers","following_url":"https://api.github.com/users/asqui/following{/other_user}","gists_url":"https://api.github.com/users/asqui/gists{/gist_id}","starred_url":"https://api.github.com/users/asqui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asqui/subscriptions","organizations_url":"https://api.github.com/users/asqui/orgs","repos_url":"https://api.github.com/users/asqui/repos","events_url":"https://api.github.com/users/asqui/events{/privacy}","received_events_url":"https://api.github.com/users/asqui/received_events","type":"User","site_admin":false},"body":"Providing one or both of these named arguments allows compare()\r\nto give more meaningful error messages on failure, which disambiguate\r\nbetween the expected and actual values.\r\n\r\nAdded 42 new unit tests to cover the new functionality across all\r\ncomparison types. General documentation not added yet but this would\r\nneed to be done before releasing the feature.\r\n\r\n(Also made some of the existing multi-line tests a bit more readable by\r\nusing textwrap.dedent() in conjunction with multi-line strings so that you\r\ncan actually see what errors will actually look like in the console rather\r\nthan just a jumble of escape codes!)","created_at":"2015-10-19T20:33:58Z","updated_at":"2015-10-19T21:22:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a065b78925c9a785539a11e7a0550d511ff79cbe","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Simplistix/testfixtures/pulls/23/commits","review_comments_url":"https://api.github.com/repos/Simplistix/testfixtures/pulls/23/comments","review_comment_url":"https://api.github.com/repos/Simplistix/testfixtures/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Simplistix/testfixtures/issues/23/comments","statuses_url":"https://api.github.com/repos/Simplistix/testfixtures/statuses/509107a5d7e10c2994c525ac28bc82591e39ad36","head":{"label":"BATS:expected_actual","ref":"expected_actual","sha":"509107a5d7e10c2994c525ac28bc82591e39ad36","user":{"login":"BATS","id":1217618,"avatar_url":"https://avatars.githubusercontent.com/u/1217618?v=3","gravatar_id":"","url":"https://api.github.com/users/BATS","html_url":"https://github.com/BATS","followers_url":"https://api.github.com/users/BATS/followers","following_url":"https://api.github.com/users/BATS/following{/other_user}","gists_url":"https://api.github.com/users/BATS/gists{/gist_id}","starred_url":"https://api.github.com/users/BATS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BATS/subscriptions","organizations_url":"https://api.github.com/users/BATS/orgs","repos_url":"https://api.github.com/users/BATS/repos","events_url":"https://api.github.com/users/BATS/events{/privacy}","received_events_url":"https://api.github.com/users/BATS/received_events","type":"Organization","site_admin":false},"repo":{"id":25154874,"name":"testfixtures","full_name":"BATS/testfixtures","owner":{"login":"BATS","id":1217618,"avatar_url":"https://avatars.githubusercontent.com/u/1217618?v=3","gravatar_id":"","url":"https://api.github.com/users/BATS","html_url":"https://github.com/BATS","followers_url":"https://api.github.com/users/BATS/followers","following_url":"https://api.github.com/users/BATS/following{/other_user}","gists_url":"https://api.github.com/users/BATS/gists{/gist_id}","starred_url":"https://api.github.com/users/BATS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BATS/subscriptions","organizations_url":"https://api.github.com/users/BATS/orgs","repos_url":"https://api.github.com/users/BATS/repos","events_url":"https://api.github.com/users/BATS/events{/privacy}","received_events_url":"https://api.github.com/users/BATS/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BATS/testfixtures","description":"TestFixtures is a collection of helpers and mock objects that are useful when writing unit tests or doc tests.","fork":true,"url":"https://api.github.com/repos/BATS/testfixtures","forks_url":"https://api.github.com/repos/BATS/testfixtures/forks","keys_url":"https://api.github.com/repos/BATS/testfixtures/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BATS/testfixtures/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BATS/testfixtures/teams","hooks_url":"https://api.github.com/repos/BATS/testfixtures/hooks","issue_events_url":"https://api.github.com/repos/BATS/testfixtures/issues/events{/number}","events_url":"https://api.github.com/repos/BATS/testfixtures/events","assignees_url":"https://api.github.com/repos/BATS/testfixtures/assignees{/user}","branches_url":"https://api.github.com/repos/BATS/testfixtures/branches{/branch}","tags_url":"https://api.github.com/repos/BATS/testfixtures/tags","blobs_url":"https://api.github.com/repos/BATS/testfixtures/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BATS/testfixtures/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BATS/testfixtures/git/refs{/sha}","trees_url":"https://api.github.com/repos/BATS/testfixtures/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BATS/testfixtures/statuses/{sha}","languages_url":"https://api.github.com/repos/BATS/testfixtures/languages","stargazers_url":"https://api.github.com/repos/BATS/testfixtures/stargazers","contributors_url":"https://api.github.com/repos/BATS/testfixtures/contributors","subscribers_url":"https://api.github.com/repos/BATS/testfixtures/subscribers","subscription_url":"https://api.github.com/repos/BATS/testfixtures/subscription","commits_url":"https://api.github.com/repos/BATS/testfixtures/commits{/sha}","git_commits_url":"https://api.github.com/repos/BATS/testfixtures/git/commits{/sha}","comments_url":"https://api.github.com/repos/BATS/testfixtures/comments{/number}","issue_comment_url":"https://api.github.com/repos/BATS/testfixtures/issues/comments{/number}","contents_url":"https://api.github.com/repos/BATS/testfixtures/contents/{+path}","compare_url":"https://api.github.com/repos/BATS/testfixtures/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BATS/testfixtures/merges","archive_url":"https://api.github.com/repos/BATS/testfixtures/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BATS/testfixtures/downloads","issues_url":"https://api.github.com/repos/BATS/testfixtures/issues{/number}","pulls_url":"https://api.github.com/repos/BATS/testfixtures/pulls{/number}","milestones_url":"https://api.github.com/repos/BATS/testfixtures/milestones{/number}","notifications_url":"https://api.github.com/repos/BATS/testfixtures/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BATS/testfixtures/labels{/name}","releases_url":"https://api.github.com/repos/BATS/testfixtures/releases{/id}","created_at":"2014-10-13T10:55:11Z","updated_at":"2014-10-13T14:56:32Z","pushed_at":"2015-10-19T20:34:46Z","git_url":"git://github.com/BATS/testfixtures.git","ssh_url":"git@github.com:BATS/testfixtures.git","clone_url":"https://github.com/BATS/testfixtures.git","svn_url":"https://github.com/BATS/testfixtures","homepage":"http://www.simplistix.co.uk/software/python/testfixtures","size":1010,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Simplistix:master","ref":"master","sha":"b42849e41213ec7c3786472ab8245328e143cca9","user":{"login":"Simplistix","id":809412,"avatar_url":"https://avatars.githubusercontent.com/u/809412?v=3","gravatar_id":"","url":"https://api.github.com/users/Simplistix","html_url":"https://github.com/Simplistix","followers_url":"https://api.github.com/users/Simplistix/followers","following_url":"https://api.github.com/users/Simplistix/following{/other_user}","gists_url":"https://api.github.com/users/Simplistix/gists{/gist_id}","starred_url":"https://api.github.com/users/Simplistix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Simplistix/subscriptions","organizations_url":"https://api.github.com/users/Simplistix/orgs","repos_url":"https://api.github.com/users/Simplistix/repos","events_url":"https://api.github.com/users/Simplistix/events{/privacy}","received_events_url":"https://api.github.com/users/Simplistix/received_events","type":"Organization","site_admin":false},"repo":{"id":1811242,"name":"testfixtures","full_name":"Simplistix/testfixtures","owner":{"login":"Simplistix","id":809412,"avatar_url":"https://avatars.githubusercontent.com/u/809412?v=3","gravatar_id":"","url":"https://api.github.com/users/Simplistix","html_url":"https://github.com/Simplistix","followers_url":"https://api.github.com/users/Simplistix/followers","following_url":"https://api.github.com/users/Simplistix/following{/other_user}","gists_url":"https://api.github.com/users/Simplistix/gists{/gist_id}","starred_url":"https://api.github.com/users/Simplistix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Simplistix/subscriptions","organizations_url":"https://api.github.com/users/Simplistix/orgs","repos_url":"https://api.github.com/users/Simplistix/repos","events_url":"https://api.github.com/users/Simplistix/events{/privacy}","received_events_url":"https://api.github.com/users/Simplistix/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Simplistix/testfixtures","description":"TestFixtures is a collection of helpers and mock objects that are useful when writing unit tests or doc tests.","fork":false,"url":"https://api.github.com/repos/Simplistix/testfixtures","forks_url":"https://api.github.com/repos/Simplistix/testfixtures/forks","keys_url":"https://api.github.com/repos/Simplistix/testfixtures/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Simplistix/testfixtures/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Simplistix/testfixtures/teams","hooks_url":"https://api.github.com/repos/Simplistix/testfixtures/hooks","issue_events_url":"https://api.github.com/repos/Simplistix/testfixtures/issues/events{/number}","events_url":"https://api.github.com/repos/Simplistix/testfixtures/events","assignees_url":"https://api.github.com/repos/Simplistix/testfixtures/assignees{/user}","branches_url":"https://api.github.com/repos/Simplistix/testfixtures/branches{/branch}","tags_url":"https://api.github.com/repos/Simplistix/testfixtures/tags","blobs_url":"https://api.github.com/repos/Simplistix/testfixtures/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Simplistix/testfixtures/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Simplistix/testfixtures/git/refs{/sha}","trees_url":"https://api.github.com/repos/Simplistix/testfixtures/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Simplistix/testfixtures/statuses/{sha}","languages_url":"https://api.github.com/repos/Simplistix/testfixtures/languages","stargazers_url":"https://api.github.com/repos/Simplistix/testfixtures/stargazers","contributors_url":"https://api.github.com/repos/Simplistix/testfixtures/contributors","subscribers_url":"https://api.github.com/repos/Simplistix/testfixtures/subscribers","subscription_url":"https://api.github.com/repos/Simplistix/testfixtures/subscription","commits_url":"https://api.github.com/repos/Simplistix/testfixtures/commits{/sha}","git_commits_url":"https://api.github.com/repos/Simplistix/testfixtures/git/commits{/sha}","comments_url":"https://api.github.com/repos/Simplistix/testfixtures/comments{/number}","issue_comment_url":"https://api.github.com/repos/Simplistix/testfixtures/issues/comments{/number}","contents_url":"https://api.github.com/repos/Simplistix/testfixtures/contents/{+path}","compare_url":"https://api.github.com/repos/Simplistix/testfixtures/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Simplistix/testfixtures/merges","archive_url":"https://api.github.com/repos/Simplistix/testfixtures/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Simplistix/testfixtures/downloads","issues_url":"https://api.github.com/repos/Simplistix/testfixtures/issues{/number}","pulls_url":"https://api.github.com/repos/Simplistix/testfixtures/pulls{/number}","milestones_url":"https://api.github.com/repos/Simplistix/testfixtures/milestones{/number}","notifications_url":"https://api.github.com/repos/Simplistix/testfixtures/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Simplistix/testfixtures/labels{/name}","releases_url":"https://api.github.com/repos/Simplistix/testfixtures/releases{/id}","created_at":"2011-05-27T18:44:50Z","updated_at":"2015-10-08T03:59:58Z","pushed_at":"2015-10-19T20:33:59Z","git_url":"git://github.com/Simplistix/testfixtures.git","ssh_url":"git@github.com:Simplistix/testfixtures.git","clone_url":"https://github.com/Simplistix/testfixtures.git","svn_url":"https://github.com/Simplistix/testfixtures","homepage":"http://www.simplistix.co.uk/software/python/testfixtures","size":1436,"stargazers_count":37,"watchers_count":37,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":3,"forks":15,"open_issues":3,"watchers":37,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Simplistix/testfixtures/pulls/23"},"html":{"href":"https://github.com/Simplistix/testfixtures/pull/23"},"issue":{"href":"https://api.github.com/repos/Simplistix/testfixtures/issues/23"},"comments":{"href":"https://api.github.com/repos/Simplistix/testfixtures/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/Simplistix/testfixtures/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/Simplistix/testfixtures/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Simplistix/testfixtures/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/Simplistix/testfixtures/statuses/509107a5d7e10c2994c525ac28bc82591e39ad36"}}}}