{"action":"created","comment":{"url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls/comments/80313315","id":80313315,"diff_hunk":"@@ -0,0 +1,224 @@\n+# ###################################################\n+# Copyright (C) 2008-2016 The Unknown Horizons Team\n+# team@unknown-horizons.org\n+# This file is part of Unknown Horizons.\n+#\n+# Unknown Horizons is free software; you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License as published by\n+# the Free Software Foundation; either version 2 of the License, or\n+# (at your option) any later version.\n+#\n+# This program is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with this program; if not, write to the\n+# Free Software Foundation, Inc.,\n+# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\n+# ###################################################\n+\n+import unittest\n+\n+import mock\n+\n+from tests.gui.helper import GuiHelper\n+\n+\n+class Widget(object):\n+\t\"\"\"\n+\tFake widget with a name, children and possible a parent. All children of this widget will\n+\tget their parent attribute set to this widget.\n+\t\"\"\"\n+\tdef __init__(self, name, children=None):\n+\t\tself.name = name\n+\t\tself.parent = None\n+\t\tself.children = children or []\n+\t\tfor c in self.children:\n+\t\t\tc.parent = self\n+\n+\tdef __repr__(self):\n+\t\treturn self.name\n+\n+\tdef __hash__(self):\n+\t\treturn id(self)\n+\n+\n+class FindWidgetTest(unittest.TestCase):\n+\t\"\"\"\n+\tTests about finding widgets in pychan's internal lists.\n+\t\"\"\"\n+\tdef setUp(self):\n+\t\tself.widgets = set()\n+\n+\t\tdef w(name, children=None):\n+\t\t\twidget = Widget(name, children)\n+\t\t\tself.widgets.add(widget)\n+\t\t\treturn widget\n+\n+\t\tself.w = w\n+\n+\t\thelper = GuiHelper(mock.Mock(), mock.Mock())\n+\t\tself.find = lambda x: helper._find(self.widgets, x)\n+\n+\tdef test_simple(self):\n+\t\t\"\"\"\n+\t\tSingle widget in the global list.\n+\t\t\"\"\"\n+\t\ttarget = self.w('target')\n+\t\tself.assertEqual(self.find('target'), target)\n+\n+\tdef test_parent(self):\n+\t\t\"\"\"\n+\t\tSingle widget with a child.\n+\t\t\"\"\"\n+\t\ttarget = self.w('target')\n+\t\tself.w('foobar', [\n+\t\t\ttarget\n+\t\t])\n+\n+\t\tself.assertEqual(self.find('target'), target)\n+\n+\tdef test_hierarchy(self):\n+\t\t\"\"\"\n+\t\tTarget widget with multiple parents and another widget with the same name, but\n+\t\twithout parent.\n+\t\t\"\"\"\n+\t\ttarget = self.w('target')\n+\n+\t\tself.w('bla', [\n+\t\t\tself.w('baz', [\n+\t\t\t\ttarget\n+\t\t\t])\n+\t\t])\n+\t\tself.w('foobar')\n+\t\tself.w('target')\n+\n+\t\tself.assertEqual(self.find('bla/baz/target'), target)\n+\n+\tdef test_hierarchy_incomplete_path(self):\n+\t\t\"\"\"\n+\t\tTarget with multiple parents, select it while omitting one parent in the search\n+\t\tpath.\n+\t\t\"\"\"\n+\t\ttarget = self.w('target')\n+\n+\t\tself.w('bla', [\n+\t\t\tself.w('baz', [\n+\t\t\t\ttarget\n+\t\t\t])\n+\t\t])\n+\t\tself.w('foobar')\n+\t\tself.w('target')\n+\n+\t\tself.assertEqual(self.find('bla/target'), target)\n+\n+\tdef test_hierarchy_returns_widget_with_best_matching_path(self):\n+\t\t\"\"\"\n+\t\tIf we have multiple matches for a path, return the one that fits most closely,\n+\t\ti.e. the one with the shortest path of names.\n+\t\t\"\"\"\n+\t\ttarget1 = self.w('target')\n+\t\ttarget2 = self.w('target')\n+\n+\t\tself.w('bla', [\n+\t\t\tself.w('baz', [\n+\t\t\t\ttarget1\n+\t\t\t])\n+\t\t])\n+\t\tself.w('bla', [\n+\t\t\ttarget2\n+\t\t])\n+\n+\t\tself.assertEqual(self.find('bla/target'), target2)\n+\n+\tdef test_ambigious_error(self):\n+\t\t\"\"\"\n+\t\tIf a single best match can't be found, an error is raised instead.\n+\t\t\"\"\"\n+\t\ttarget1 = self.w('target')\n+\t\ttarget2 = self.w('target')\n+\n+\t\tself.w('bla', [\n+\t\t\ttarget1\n+\t\t])\n+\t\tself.w('bla', [\n+\t\t\ttarget2\n+\t\t])\n+\n+\t\ttry:\n+\t\t\tself.find('bla/target')\n+\t\texcept Exception as e:\n+\t\t\tself.assertEqual(str(e), 'Ambigious specification bla/target, found 2 matches')","path":"tests/gui/test_helper_find.py","position":153,"original_position":153,"commit_id":"9a2cc015bbcce87f64ee221821d44faef983f498","original_commit_id":"9a2cc015bbcce87f64ee221821d44faef983f498","user":{"login":"squiddy","id":50333,"avatar_url":"https://avatars.githubusercontent.com/u/50333?v=3","gravatar_id":"","url":"https://api.github.com/users/squiddy","html_url":"https://github.com/squiddy","followers_url":"https://api.github.com/users/squiddy/followers","following_url":"https://api.github.com/users/squiddy/following{/other_user}","gists_url":"https://api.github.com/users/squiddy/gists{/gist_id}","starred_url":"https://api.github.com/users/squiddy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squiddy/subscriptions","organizations_url":"https://api.github.com/users/squiddy/orgs","repos_url":"https://api.github.com/users/squiddy/repos","events_url":"https://api.github.com/users/squiddy/events{/privacy}","received_events_url":"https://api.github.com/users/squiddy/received_events","type":"User","site_admin":false},"body":"I support I could have added a custom Exception class for easier assertion, but I didn't feel like it would be worth it.","created_at":"2016-09-23T19:40:34Z","updated_at":"2016-09-23T19:40:34Z","html_url":"https://github.com/unknown-horizons/unknown-horizons/pull/2488#discussion_r80313315","pull_request_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls/2488","_links":{"self":{"href":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls/comments/80313315"},"html":{"href":"https://github.com/unknown-horizons/unknown-horizons/pull/2488#discussion_r80313315"},"pull_request":{"href":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls/2488"}}},"pull_request":{"url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls/2488","id":86402768,"html_url":"https://github.com/unknown-horizons/unknown-horizons/pull/2488","diff_url":"https://github.com/unknown-horizons/unknown-horizons/pull/2488.diff","patch_url":"https://github.com/unknown-horizons/unknown-horizons/pull/2488.patch","issue_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/issues/2488","number":2488,"state":"open","locked":false,"title":"Reimplement finding widgets in gui tests","user":{"login":"squiddy","id":50333,"avatar_url":"https://avatars.githubusercontent.com/u/50333?v=3","gravatar_id":"","url":"https://api.github.com/users/squiddy","html_url":"https://github.com/squiddy","followers_url":"https://api.github.com/users/squiddy/followers","following_url":"https://api.github.com/users/squiddy/following{/other_user}","gists_url":"https://api.github.com/users/squiddy/gists{/gist_id}","starred_url":"https://api.github.com/users/squiddy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squiddy/subscriptions","organizations_url":"https://api.github.com/users/squiddy/orgs","repos_url":"https://api.github.com/users/squiddy/repos","events_url":"https://api.github.com/users/squiddy/events{/privacy}","received_events_url":"https://api.github.com/users/squiddy/received_events","type":"User","site_admin":false},"body":null,"created_at":"2016-09-22T19:51:40Z","updated_at":"2016-09-23T19:40:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a5b109d82190715f857b389659842c5960f9a80d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls/2488/commits","review_comments_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls/2488/comments","review_comment_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls/comments{/number}","comments_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/issues/2488/comments","statuses_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/statuses/9a2cc015bbcce87f64ee221821d44faef983f498","head":{"label":"squiddy:gui-tests-find-reimplementation","ref":"gui-tests-find-reimplementation","sha":"9a2cc015bbcce87f64ee221821d44faef983f498","user":{"login":"squiddy","id":50333,"avatar_url":"https://avatars.githubusercontent.com/u/50333?v=3","gravatar_id":"","url":"https://api.github.com/users/squiddy","html_url":"https://github.com/squiddy","followers_url":"https://api.github.com/users/squiddy/followers","following_url":"https://api.github.com/users/squiddy/following{/other_user}","gists_url":"https://api.github.com/users/squiddy/gists{/gist_id}","starred_url":"https://api.github.com/users/squiddy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squiddy/subscriptions","organizations_url":"https://api.github.com/users/squiddy/orgs","repos_url":"https://api.github.com/users/squiddy/repos","events_url":"https://api.github.com/users/squiddy/events{/privacy}","received_events_url":"https://api.github.com/users/squiddy/received_events","type":"User","site_admin":false},"repo":{"id":6008924,"name":"unknown-horizons","full_name":"squiddy/unknown-horizons","owner":{"login":"squiddy","id":50333,"avatar_url":"https://avatars.githubusercontent.com/u/50333?v=3","gravatar_id":"","url":"https://api.github.com/users/squiddy","html_url":"https://github.com/squiddy","followers_url":"https://api.github.com/users/squiddy/followers","following_url":"https://api.github.com/users/squiddy/following{/other_user}","gists_url":"https://api.github.com/users/squiddy/gists{/gist_id}","starred_url":"https://api.github.com/users/squiddy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squiddy/subscriptions","organizations_url":"https://api.github.com/users/squiddy/orgs","repos_url":"https://api.github.com/users/squiddy/repos","events_url":"https://api.github.com/users/squiddy/events{/privacy}","received_events_url":"https://api.github.com/users/squiddy/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/squiddy/unknown-horizons","description":"Unknown Horizons official code repository","fork":true,"url":"https://api.github.com/repos/squiddy/unknown-horizons","forks_url":"https://api.github.com/repos/squiddy/unknown-horizons/forks","keys_url":"https://api.github.com/repos/squiddy/unknown-horizons/keys{/key_id}","collaborators_url":"https://api.github.com/repos/squiddy/unknown-horizons/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/squiddy/unknown-horizons/teams","hooks_url":"https://api.github.com/repos/squiddy/unknown-horizons/hooks","issue_events_url":"https://api.github.com/repos/squiddy/unknown-horizons/issues/events{/number}","events_url":"https://api.github.com/repos/squiddy/unknown-horizons/events","assignees_url":"https://api.github.com/repos/squiddy/unknown-horizons/assignees{/user}","branches_url":"https://api.github.com/repos/squiddy/unknown-horizons/branches{/branch}","tags_url":"https://api.github.com/repos/squiddy/unknown-horizons/tags","blobs_url":"https://api.github.com/repos/squiddy/unknown-horizons/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/squiddy/unknown-horizons/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/squiddy/unknown-horizons/git/refs{/sha}","trees_url":"https://api.github.com/repos/squiddy/unknown-horizons/git/trees{/sha}","statuses_url":"https://api.github.com/repos/squiddy/unknown-horizons/statuses/{sha}","languages_url":"https://api.github.com/repos/squiddy/unknown-horizons/languages","stargazers_url":"https://api.github.com/repos/squiddy/unknown-horizons/stargazers","contributors_url":"https://api.github.com/repos/squiddy/unknown-horizons/contributors","subscribers_url":"https://api.github.com/repos/squiddy/unknown-horizons/subscribers","subscription_url":"https://api.github.com/repos/squiddy/unknown-horizons/subscription","commits_url":"https://api.github.com/repos/squiddy/unknown-horizons/commits{/sha}","git_commits_url":"https://api.github.com/repos/squiddy/unknown-horizons/git/commits{/sha}","comments_url":"https://api.github.com/repos/squiddy/unknown-horizons/comments{/number}","issue_comment_url":"https://api.github.com/repos/squiddy/unknown-horizons/issues/comments{/number}","contents_url":"https://api.github.com/repos/squiddy/unknown-horizons/contents/{+path}","compare_url":"https://api.github.com/repos/squiddy/unknown-horizons/compare/{base}...{head}","merges_url":"https://api.github.com/repos/squiddy/unknown-horizons/merges","archive_url":"https://api.github.com/repos/squiddy/unknown-horizons/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/squiddy/unknown-horizons/downloads","issues_url":"https://api.github.com/repos/squiddy/unknown-horizons/issues{/number}","pulls_url":"https://api.github.com/repos/squiddy/unknown-horizons/pulls{/number}","milestones_url":"https://api.github.com/repos/squiddy/unknown-horizons/milestones{/number}","notifications_url":"https://api.github.com/repos/squiddy/unknown-horizons/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/squiddy/unknown-horizons/labels{/name}","releases_url":"https://api.github.com/repos/squiddy/unknown-horizons/releases{/id}","deployments_url":"https://api.github.com/repos/squiddy/unknown-horizons/deployments","created_at":"2012-09-29T12:35:47Z","updated_at":"2016-09-17T18:42:19Z","pushed_at":"2016-09-23T19:32:15Z","git_url":"git://github.com/squiddy/unknown-horizons.git","ssh_url":"git@github.com:squiddy/unknown-horizons.git","clone_url":"https://github.com/squiddy/unknown-horizons.git","svn_url":"https://github.com/squiddy/unknown-horizons","homepage":"http://www.unknown-horizons.org","size":487168,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":false,"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":"unknown-horizons:master","ref":"master","sha":"dfcb3080c4e6782c427ec23306428e4e5de21326","user":{"login":"unknown-horizons","id":372796,"avatar_url":"https://avatars.githubusercontent.com/u/372796?v=3","gravatar_id":"","url":"https://api.github.com/users/unknown-horizons","html_url":"https://github.com/unknown-horizons","followers_url":"https://api.github.com/users/unknown-horizons/followers","following_url":"https://api.github.com/users/unknown-horizons/following{/other_user}","gists_url":"https://api.github.com/users/unknown-horizons/gists{/gist_id}","starred_url":"https://api.github.com/users/unknown-horizons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unknown-horizons/subscriptions","organizations_url":"https://api.github.com/users/unknown-horizons/orgs","repos_url":"https://api.github.com/users/unknown-horizons/repos","events_url":"https://api.github.com/users/unknown-horizons/events{/privacy}","received_events_url":"https://api.github.com/users/unknown-horizons/received_events","type":"Organization","site_admin":false},"repo":{"id":856193,"name":"unknown-horizons","full_name":"unknown-horizons/unknown-horizons","owner":{"login":"unknown-horizons","id":372796,"avatar_url":"https://avatars.githubusercontent.com/u/372796?v=3","gravatar_id":"","url":"https://api.github.com/users/unknown-horizons","html_url":"https://github.com/unknown-horizons","followers_url":"https://api.github.com/users/unknown-horizons/followers","following_url":"https://api.github.com/users/unknown-horizons/following{/other_user}","gists_url":"https://api.github.com/users/unknown-horizons/gists{/gist_id}","starred_url":"https://api.github.com/users/unknown-horizons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unknown-horizons/subscriptions","organizations_url":"https://api.github.com/users/unknown-horizons/orgs","repos_url":"https://api.github.com/users/unknown-horizons/repos","events_url":"https://api.github.com/users/unknown-horizons/events{/privacy}","received_events_url":"https://api.github.com/users/unknown-horizons/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/unknown-horizons/unknown-horizons","description":"Unknown Horizons official code repository","fork":false,"url":"https://api.github.com/repos/unknown-horizons/unknown-horizons","forks_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/forks","keys_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/keys{/key_id}","collaborators_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/teams","hooks_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/hooks","issue_events_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/issues/events{/number}","events_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/events","assignees_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/assignees{/user}","branches_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/branches{/branch}","tags_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/tags","blobs_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/git/refs{/sha}","trees_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/git/trees{/sha}","statuses_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/statuses/{sha}","languages_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/languages","stargazers_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/stargazers","contributors_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/contributors","subscribers_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/subscribers","subscription_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/subscription","commits_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/commits{/sha}","git_commits_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/git/commits{/sha}","comments_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/comments{/number}","issue_comment_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/issues/comments{/number}","contents_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/contents/{+path}","compare_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/compare/{base}...{head}","merges_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/merges","archive_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/downloads","issues_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/issues{/number}","pulls_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls{/number}","milestones_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/milestones{/number}","notifications_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/labels{/name}","releases_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/releases{/id}","deployments_url":"https://api.github.com/repos/unknown-horizons/unknown-horizons/deployments","created_at":"2010-08-23T08:48:29Z","updated_at":"2016-09-22T21:59:01Z","pushed_at":"2016-09-23T19:34:40Z","git_url":"git://github.com/unknown-horizons/unknown-horizons.git","ssh_url":"git@github.com:unknown-horizons/unknown-horizons.git","clone_url":"https://github.com/unknown-horizons/unknown-horizons.git","svn_url":"https://github.com/unknown-horizons/unknown-horizons","homepage":"http://www.unknown-horizons.org","size":524096,"stargazers_count":340,"watchers_count":340,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":127,"mirror_url":null,"open_issues_count":266,"forks":127,"open_issues":266,"watchers":340,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls/2488"},"html":{"href":"https://github.com/unknown-horizons/unknown-horizons/pull/2488"},"issue":{"href":"https://api.github.com/repos/unknown-horizons/unknown-horizons/issues/2488"},"comments":{"href":"https://api.github.com/repos/unknown-horizons/unknown-horizons/issues/2488/comments"},"review_comments":{"href":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls/2488/comments"},"review_comment":{"href":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/unknown-horizons/unknown-horizons/pulls/2488/commits"},"statuses":{"href":"https://api.github.com/repos/unknown-horizons/unknown-horizons/statuses/9a2cc015bbcce87f64ee221821d44faef983f498"}}}}
{"actor":{"display_login":"squiddy"}}