{"action":"created","comment":{"url":"https://api.github.com/repos/coala-analyzer/coala/pulls/comments/66288405","id":66288405,"diff_hunk":"@@ -0,0 +1,143 @@\n+import unittest\n+import re\n+import os\n+import time\n+\n+from pyprint.NullPrinter import NullPrinter\n+\n+from coalib.misc.Caching import FileCache\n+from coalib.misc.CachingUtilities import (\n+    get_settings_hash, settings_changed, update_settings_db,\n+    pickle_load, pickle_dump)\n+from coalib.output.printers.LogPrinter import LogPrinter\n+from coalib import coala\n+from coalib.misc.ContextManagers import prepare_file\n+from tests.TestUtilities import execute_coala, bear_test_module\n+\n+\n+class CachingTest(unittest.TestCase):\n+\n+    def setUp(self):\n+        current_dir = os.path.split(__file__)[0]\n+        self.caching_test_dir = os.path.join(\n+            current_dir,\n+            \"caching_testfiles\")\n+        self.log_printer = LogPrinter(NullPrinter())\n+        self.cache = FileCache(self.log_printer, \"coala_test\", flush_cache=True)\n+\n+    def test_file_tracking(self):\n+        self.cache.track_files({\"test.c\", \"file.py\"})\n+        self.assertEqual(self.cache.data, {\"test.c\": -1, \"file.py\": -1})\n+\n+        self.cache.untrack_files({\"test.c\"})\n+        self.assertFalse(\"test.c\" in self.cache.data)\n+        self.assertTrue(\"file.py\" in self.cache.data)\n+\n+        self.cache.untrack_files({\"test.c\", \"file.py\"})\n+        self.assertFalse(\"test.c\" in self.cache.data)\n+        self.assertFalse(\"file.py\" in self.cache.data)\n+\n+    def test_write(self):\n+        self.cache.track_files({\"test2.c\"})\n+        self.assertEqual(self.cache.data[\"test2.c\"], -1)\n+\n+        self.cache.write()\n+        self.assertNotEqual(self.cache.data[\"test2.c\"], -1)\n+\n+    def test_get_uncached_files(self):\n+        file_path = os.path.join(self.caching_test_dir, \"test.c\")\n+        cache = FileCache(self.log_printer, \"coala_test3\", flush_cache=True)\n+\n+        # Since this is a new FileCache object, the return must be the full set\n+        self.assertEqual(cache.get_uncached_files({file_path}), {file_path})\n+\n+        open(file_path, \"w\").close()\n+        cache.track_files({file_path})\n+        self.assertEqual(cache.get_uncached_files({file_path}), {file_path})\n+\n+        cache.write()\n+        self.assertEqual(cache.get_uncached_files({file_path}), set())\n+\n+        # Simulate changing the file and then getting uncached files\n+        # Since the file has been edited since the last run it's returned\n+        time.sleep(1)\n+        open(file_path, \"w\").close()\n+        cache = FileCache(self.log_printer, \"coala_test3\", flush_cache=False)\n+        cache.track_files({file_path})\n+        self.assertEqual(cache.get_uncached_files({file_path}), {file_path})\n+        cache.write()\n+\n+        # Not changing the file should NOT return it the next time\n+        time.sleep(1)\n+        cache = FileCache(self.log_printer, \"coala_test3\", flush_cache=False)\n+        cache.track_files({file_path})\n+        print(cache.data)\n+        self.assertEqual(cache.get_uncached_files({file_path}), set())\n+        cache.write()\n+\n+    def test_persistence(self):\n+        with FileCache(self.log_printer, \"test3\", flush_cache=True) as cache:\n+            cache.track_files({\"file.c\"})\n+        self.assertTrue(\"file.c\" in cache.data)\n+\n+        with FileCache(self.log_printer, \"test3\", flush_cache=False) as cache:\n+            self.assertTrue(\"file.c\" in cache.data)\n+\n+    def test_time_travel(self):\n+        cache = FileCache(self.log_printer, \"coala_test2\", flush_cache=True)\n+        cache.track_files({\"file.c\"})\n+        cache.write()\n+        self.assertTrue(\"file.c\" in cache.data)\n+\n+        cache_data = pickle_load(self.log_printer, \"coala_test2\", {})\n+        # Back to the future :)\n+        # 2000000000 corresponds to the future year 2033\n+        cache_data[\"time\"] = 2000000000","path":"tests/misc/CachingTest.py","position":95,"original_position":95,"commit_id":"a8c34e4f84c8e17c5573febebc728f1be21ca97c","original_commit_id":"d9647dca004d8c02164b3be091c709c05ab279f8","user":{"login":"sils1297","id":5716520,"avatar_url":"https://avatars.githubusercontent.com/u/5716520?v=3","gravatar_id":"","url":"https://api.github.com/users/sils1297","html_url":"https://github.com/sils1297","followers_url":"https://api.github.com/users/sils1297/followers","following_url":"https://api.github.com/users/sils1297/following{/other_user}","gists_url":"https://api.github.com/users/sils1297/gists{/gist_id}","starred_url":"https://api.github.com/users/sils1297/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sils1297/subscriptions","organizations_url":"https://api.github.com/users/sils1297/orgs","repos_url":"https://api.github.com/users/sils1297/repos","events_url":"https://api.github.com/users/sils1297/events{/privacy}","received_events_url":"https://api.github.com/users/sils1297/received_events","type":"User","site_admin":false},"body":"can you rather take current time and add a bit?","created_at":"2016-06-08T16:19:41Z","updated_at":"2016-06-08T16:19:41Z","html_url":"https://github.com/coala-analyzer/coala/pull/2016#discussion_r66288405","pull_request_url":"https://api.github.com/repos/coala-analyzer/coala/pulls/2016","_links":{"self":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/comments/66288405"},"html":{"href":"https://github.com/coala-analyzer/coala/pull/2016#discussion_r66288405"},"pull_request":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/2016"}}},"pull_request":{"url":"https://api.github.com/repos/coala-analyzer/coala/pulls/2016","id":66533143,"html_url":"https://github.com/coala-analyzer/coala/pull/2016","diff_url":"https://github.com/coala-analyzer/coala/pull/2016.diff","patch_url":"https://github.com/coala-analyzer/coala/pull/2016.patch","issue_url":"https://api.github.com/repos/coala-analyzer/coala/issues/2016","number":2016,"state":"open","locked":false,"title":"coala: Add file caching and remove Tagging","user":{"login":"hypothesist","id":7521600,"avatar_url":"https://avatars.githubusercontent.com/u/7521600?v=3","gravatar_id":"","url":"https://api.github.com/users/hypothesist","html_url":"https://github.com/hypothesist","followers_url":"https://api.github.com/users/hypothesist/followers","following_url":"https://api.github.com/users/hypothesist/following{/other_user}","gists_url":"https://api.github.com/users/hypothesist/gists{/gist_id}","starred_url":"https://api.github.com/users/hypothesist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hypothesist/subscriptions","organizations_url":"https://api.github.com/users/hypothesist/orgs","repos_url":"https://api.github.com/users/hypothesist/repos","events_url":"https://api.github.com/users/hypothesist/events{/privacy}","received_events_url":"https://api.github.com/users/hypothesist/received_events","type":"User","site_admin":false},"body":"With `--caching` the user can run coala only on those files that\r\nhad changed since the last time coala was run. This should improve\r\nthe running time of coala.","created_at":"2016-04-14T18:39:27Z","updated_at":"2016-06-08T16:19:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2e35079f2be70cb21c4e8858927f58be0e4e7697","assignee":null,"milestone":{"url":"https://api.github.com/repos/coala-analyzer/coala/milestones/8","html_url":"https://github.com/coala-analyzer/coala/milestones/0.7","labels_url":"https://api.github.com/repos/coala-analyzer/coala/milestones/8/labels","id":1728306,"number":8,"title":"0.7","description":"","creator":{"login":"sils1297","id":5716520,"avatar_url":"https://avatars.githubusercontent.com/u/5716520?v=3","gravatar_id":"","url":"https://api.github.com/users/sils1297","html_url":"https://github.com/sils1297","followers_url":"https://api.github.com/users/sils1297/followers","following_url":"https://api.github.com/users/sils1297/following{/other_user}","gists_url":"https://api.github.com/users/sils1297/gists{/gist_id}","starred_url":"https://api.github.com/users/sils1297/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sils1297/subscriptions","organizations_url":"https://api.github.com/users/sils1297/orgs","repos_url":"https://api.github.com/users/sils1297/repos","events_url":"https://api.github.com/users/sils1297/events{/privacy}","received_events_url":"https://api.github.com/users/sils1297/received_events","type":"User","site_admin":false},"open_issues":17,"closed_issues":18,"state":"open","created_at":"2016-04-25T08:01:21Z","updated_at":"2016-06-08T08:32:32Z","due_on":"2016-05-30T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/coala-analyzer/coala/pulls/2016/commits","review_comments_url":"https://api.github.com/repos/coala-analyzer/coala/pulls/2016/comments","review_comment_url":"https://api.github.com/repos/coala-analyzer/coala/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coala-analyzer/coala/issues/2016/comments","statuses_url":"https://api.github.com/repos/coala-analyzer/coala/statuses/a8c34e4f84c8e17c5573febebc728f1be21ca97c","head":{"label":"coala-analyzer:hypothesist/wip","ref":"hypothesist/wip","sha":"a8c34e4f84c8e17c5573febebc728f1be21ca97c","user":{"login":"coala-analyzer","id":10620750,"avatar_url":"https://avatars.githubusercontent.com/u/10620750?v=3","gravatar_id":"","url":"https://api.github.com/users/coala-analyzer","html_url":"https://github.com/coala-analyzer","followers_url":"https://api.github.com/users/coala-analyzer/followers","following_url":"https://api.github.com/users/coala-analyzer/following{/other_user}","gists_url":"https://api.github.com/users/coala-analyzer/gists{/gist_id}","starred_url":"https://api.github.com/users/coala-analyzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coala-analyzer/subscriptions","organizations_url":"https://api.github.com/users/coala-analyzer/orgs","repos_url":"https://api.github.com/users/coala-analyzer/repos","events_url":"https://api.github.com/users/coala-analyzer/events{/privacy}","received_events_url":"https://api.github.com/users/coala-analyzer/received_events","type":"Organization","site_admin":false},"repo":{"id":19816973,"name":"coala","full_name":"coala-analyzer/coala","owner":{"login":"coala-analyzer","id":10620750,"avatar_url":"https://avatars.githubusercontent.com/u/10620750?v=3","gravatar_id":"","url":"https://api.github.com/users/coala-analyzer","html_url":"https://github.com/coala-analyzer","followers_url":"https://api.github.com/users/coala-analyzer/followers","following_url":"https://api.github.com/users/coala-analyzer/following{/other_user}","gists_url":"https://api.github.com/users/coala-analyzer/gists{/gist_id}","starred_url":"https://api.github.com/users/coala-analyzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coala-analyzer/subscriptions","organizations_url":"https://api.github.com/users/coala-analyzer/orgs","repos_url":"https://api.github.com/users/coala-analyzer/repos","events_url":"https://api.github.com/users/coala-analyzer/events{/privacy}","received_events_url":"https://api.github.com/users/coala-analyzer/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coala-analyzer/coala","description":"Easy to use code analysis framework/application - yes! For all languages!","fork":false,"url":"https://api.github.com/repos/coala-analyzer/coala","forks_url":"https://api.github.com/repos/coala-analyzer/coala/forks","keys_url":"https://api.github.com/repos/coala-analyzer/coala/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coala-analyzer/coala/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coala-analyzer/coala/teams","hooks_url":"https://api.github.com/repos/coala-analyzer/coala/hooks","issue_events_url":"https://api.github.com/repos/coala-analyzer/coala/issues/events{/number}","events_url":"https://api.github.com/repos/coala-analyzer/coala/events","assignees_url":"https://api.github.com/repos/coala-analyzer/coala/assignees{/user}","branches_url":"https://api.github.com/repos/coala-analyzer/coala/branches{/branch}","tags_url":"https://api.github.com/repos/coala-analyzer/coala/tags","blobs_url":"https://api.github.com/repos/coala-analyzer/coala/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coala-analyzer/coala/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coala-analyzer/coala/git/refs{/sha}","trees_url":"https://api.github.com/repos/coala-analyzer/coala/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coala-analyzer/coala/statuses/{sha}","languages_url":"https://api.github.com/repos/coala-analyzer/coala/languages","stargazers_url":"https://api.github.com/repos/coala-analyzer/coala/stargazers","contributors_url":"https://api.github.com/repos/coala-analyzer/coala/contributors","subscribers_url":"https://api.github.com/repos/coala-analyzer/coala/subscribers","subscription_url":"https://api.github.com/repos/coala-analyzer/coala/subscription","commits_url":"https://api.github.com/repos/coala-analyzer/coala/commits{/sha}","git_commits_url":"https://api.github.com/repos/coala-analyzer/coala/git/commits{/sha}","comments_url":"https://api.github.com/repos/coala-analyzer/coala/comments{/number}","issue_comment_url":"https://api.github.com/repos/coala-analyzer/coala/issues/comments{/number}","contents_url":"https://api.github.com/repos/coala-analyzer/coala/contents/{+path}","compare_url":"https://api.github.com/repos/coala-analyzer/coala/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coala-analyzer/coala/merges","archive_url":"https://api.github.com/repos/coala-analyzer/coala/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coala-analyzer/coala/downloads","issues_url":"https://api.github.com/repos/coala-analyzer/coala/issues{/number}","pulls_url":"https://api.github.com/repos/coala-analyzer/coala/pulls{/number}","milestones_url":"https://api.github.com/repos/coala-analyzer/coala/milestones{/number}","notifications_url":"https://api.github.com/repos/coala-analyzer/coala/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coala-analyzer/coala/labels{/name}","releases_url":"https://api.github.com/repos/coala-analyzer/coala/releases{/id}","deployments_url":"https://api.github.com/repos/coala-analyzer/coala/deployments","created_at":"2014-05-15T11:35:34Z","updated_at":"2016-06-08T03:22:04Z","pushed_at":"2016-06-08T16:01:49Z","git_url":"git://github.com/coala-analyzer/coala.git","ssh_url":"git@github.com:coala-analyzer/coala.git","clone_url":"https://github.com/coala-analyzer/coala.git","svn_url":"https://github.com/coala-analyzer/coala","homepage":"http://coala-analyzer.org/","size":11868,"stargazers_count":216,"watchers_count":216,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":142,"mirror_url":null,"open_issues_count":182,"forks":142,"open_issues":182,"watchers":216,"default_branch":"master"}},"base":{"label":"coala-analyzer:master","ref":"master","sha":"fc9cee80da44e1e56f53909b6d93d28acd2a36bb","user":{"login":"coala-analyzer","id":10620750,"avatar_url":"https://avatars.githubusercontent.com/u/10620750?v=3","gravatar_id":"","url":"https://api.github.com/users/coala-analyzer","html_url":"https://github.com/coala-analyzer","followers_url":"https://api.github.com/users/coala-analyzer/followers","following_url":"https://api.github.com/users/coala-analyzer/following{/other_user}","gists_url":"https://api.github.com/users/coala-analyzer/gists{/gist_id}","starred_url":"https://api.github.com/users/coala-analyzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coala-analyzer/subscriptions","organizations_url":"https://api.github.com/users/coala-analyzer/orgs","repos_url":"https://api.github.com/users/coala-analyzer/repos","events_url":"https://api.github.com/users/coala-analyzer/events{/privacy}","received_events_url":"https://api.github.com/users/coala-analyzer/received_events","type":"Organization","site_admin":false},"repo":{"id":19816973,"name":"coala","full_name":"coala-analyzer/coala","owner":{"login":"coala-analyzer","id":10620750,"avatar_url":"https://avatars.githubusercontent.com/u/10620750?v=3","gravatar_id":"","url":"https://api.github.com/users/coala-analyzer","html_url":"https://github.com/coala-analyzer","followers_url":"https://api.github.com/users/coala-analyzer/followers","following_url":"https://api.github.com/users/coala-analyzer/following{/other_user}","gists_url":"https://api.github.com/users/coala-analyzer/gists{/gist_id}","starred_url":"https://api.github.com/users/coala-analyzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coala-analyzer/subscriptions","organizations_url":"https://api.github.com/users/coala-analyzer/orgs","repos_url":"https://api.github.com/users/coala-analyzer/repos","events_url":"https://api.github.com/users/coala-analyzer/events{/privacy}","received_events_url":"https://api.github.com/users/coala-analyzer/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coala-analyzer/coala","description":"Easy to use code analysis framework/application - yes! For all languages!","fork":false,"url":"https://api.github.com/repos/coala-analyzer/coala","forks_url":"https://api.github.com/repos/coala-analyzer/coala/forks","keys_url":"https://api.github.com/repos/coala-analyzer/coala/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coala-analyzer/coala/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coala-analyzer/coala/teams","hooks_url":"https://api.github.com/repos/coala-analyzer/coala/hooks","issue_events_url":"https://api.github.com/repos/coala-analyzer/coala/issues/events{/number}","events_url":"https://api.github.com/repos/coala-analyzer/coala/events","assignees_url":"https://api.github.com/repos/coala-analyzer/coala/assignees{/user}","branches_url":"https://api.github.com/repos/coala-analyzer/coala/branches{/branch}","tags_url":"https://api.github.com/repos/coala-analyzer/coala/tags","blobs_url":"https://api.github.com/repos/coala-analyzer/coala/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coala-analyzer/coala/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coala-analyzer/coala/git/refs{/sha}","trees_url":"https://api.github.com/repos/coala-analyzer/coala/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coala-analyzer/coala/statuses/{sha}","languages_url":"https://api.github.com/repos/coala-analyzer/coala/languages","stargazers_url":"https://api.github.com/repos/coala-analyzer/coala/stargazers","contributors_url":"https://api.github.com/repos/coala-analyzer/coala/contributors","subscribers_url":"https://api.github.com/repos/coala-analyzer/coala/subscribers","subscription_url":"https://api.github.com/repos/coala-analyzer/coala/subscription","commits_url":"https://api.github.com/repos/coala-analyzer/coala/commits{/sha}","git_commits_url":"https://api.github.com/repos/coala-analyzer/coala/git/commits{/sha}","comments_url":"https://api.github.com/repos/coala-analyzer/coala/comments{/number}","issue_comment_url":"https://api.github.com/repos/coala-analyzer/coala/issues/comments{/number}","contents_url":"https://api.github.com/repos/coala-analyzer/coala/contents/{+path}","compare_url":"https://api.github.com/repos/coala-analyzer/coala/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coala-analyzer/coala/merges","archive_url":"https://api.github.com/repos/coala-analyzer/coala/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coala-analyzer/coala/downloads","issues_url":"https://api.github.com/repos/coala-analyzer/coala/issues{/number}","pulls_url":"https://api.github.com/repos/coala-analyzer/coala/pulls{/number}","milestones_url":"https://api.github.com/repos/coala-analyzer/coala/milestones{/number}","notifications_url":"https://api.github.com/repos/coala-analyzer/coala/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coala-analyzer/coala/labels{/name}","releases_url":"https://api.github.com/repos/coala-analyzer/coala/releases{/id}","deployments_url":"https://api.github.com/repos/coala-analyzer/coala/deployments","created_at":"2014-05-15T11:35:34Z","updated_at":"2016-06-08T03:22:04Z","pushed_at":"2016-06-08T16:01:49Z","git_url":"git://github.com/coala-analyzer/coala.git","ssh_url":"git@github.com:coala-analyzer/coala.git","clone_url":"https://github.com/coala-analyzer/coala.git","svn_url":"https://github.com/coala-analyzer/coala","homepage":"http://coala-analyzer.org/","size":11868,"stargazers_count":216,"watchers_count":216,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":142,"mirror_url":null,"open_issues_count":182,"forks":142,"open_issues":182,"watchers":216,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/2016"},"html":{"href":"https://github.com/coala-analyzer/coala/pull/2016"},"issue":{"href":"https://api.github.com/repos/coala-analyzer/coala/issues/2016"},"comments":{"href":"https://api.github.com/repos/coala-analyzer/coala/issues/2016/comments"},"review_comments":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/2016/comments"},"review_comment":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/2016/commits"},"statuses":{"href":"https://api.github.com/repos/coala-analyzer/coala/statuses/a8c34e4f84c8e17c5573febebc728f1be21ca97c"}}}}
{"actor":{"display_login":"sils1297"}}