{"action":"created","comment":{"url":"https://api.github.com/repos/giampaolo/psutil/pulls/comments/47667740","id":47667740,"diff_hunk":"@@ -472,6 +480,73 @@ def test_procfs_path(self):\n             psutil.PROCFS_PATH = \"/proc\"\n             os.rmdir(tdir)\n \n+    def test_psutil_is_reloadable(self):\n+        imp.reload(psutil)\n+\n+    def test_no_procfs_for_import(self):\n+        my_procfs = tempfile.mkdtemp()\n+\n+        with open(os.path.join(my_procfs, 'stat'), 'w') as f:\n+            f.write('cpu   0 0 0 0 0 0 0 0 0 0\\n')\n+            f.write('cpu0  0 0 0 0 0 0 0 0 0 0\\n')\n+            f.write('cpu1  0 0 0 0 0 0 0 0 0 0\\n')\n+\n+        self.assertNotAlmostEqual(psutil.cpu_percent(), 0)\n+        self.assertNotAlmostEqual(sum(psutil.cpu_times_percent()), 0)\n+        try:\n+            orig_open = open\n+\n+            def open_mock(name, *args):\n+                if name.startswith('/proc'):\n+                    # simulate an ENOENT\n+                    raise IOError('rejecting access to /proc')\n+                return orig_open(name, *args)\n+            patch_point = 'builtins.open' if PY3 else '__builtin__.open'\n+            with mock.patch(patch_point, side_effect=open_mock):\n+                imp.reload(psutil)\n+\n+                self.assertRaises(IOError, psutil.cpu_times)\n+                self.assertRaises(IOError, psutil.cpu_times, percpu=True)\n+                self.assertRaises(IOError, psutil.cpu_percent)\n+                self.assertRaises(IOError, psutil.cpu_percent, percpu=True)\n+                self.assertRaises(IOError, psutil.cpu_times_percent)\n+                self.assertRaises(\n+                    IOError, psutil.cpu_times_percent, percpu=True)\n+\n+                psutil.PROCFS_PATH = my_procfs\n+\n+                self.assertAlmostEqual(psutil.cpu_percent(), 0)\n+                self.assertAlmostEqual(sum(psutil.cpu_times_percent()), 0)\n+\n+                # since we don't know the number of CPUs at import time,\n+                # we awkwardly say there are none until the second call\n+                per_cpu_percent = psutil.cpu_percent(percpu=True)\n+                self.assertEqual(len(per_cpu_percent), 0)\n+                self.assertAlmostEqual(sum(per_cpu_percent), 0)\n+\n+                # ditto awkward length\n+                per_cpu_times_percent = psutil.cpu_times_percent(percpu=True)\n+                self.assertEqual(len(per_cpu_times_percent), 0)\n+                self.assertAlmostEqual(sum(map(sum, per_cpu_percent)), 0)\n+\n+                # much user, very busy\n+                with open(os.path.join(my_procfs, 'stat'), 'w') as f:\n+                    f.write('cpu   1 0 0 0 0 0 0 0 0 0\\n')\n+                    f.write('cpu0  1 0 0 0 0 0 0 0 0 0\\n')\n+                    f.write('cpu1  1 0 0 0 0 0 0 0 0 0\\n')\n+\n+                self.assertNotAlmostEqual(psutil.cpu_percent(), 0)\n+                self.assertNotAlmostEqual(\n+                    sum(psutil.cpu_percent(percpu=True)), 0)\n+                self.assertNotAlmostEqual(sum(psutil.cpu_times_percent()), 0)\n+                self.assertNotAlmostEqual(\n+                    sum(map(sum, psutil.cpu_times_percent(percpu=True))), 0)\n+        finally:\n+            shutil.rmtree(my_procfs)\n+            imp.reload(psutil)\n+\n+        assert psutil.PROCFS_PATH == '/proc'","path":"test/_linux.py","position":91,"original_position":91,"commit_id":"3c26133cdc682833326f8b0a45c749f4a6e38620","original_commit_id":"3c26133cdc682833326f8b0a45c749f4a6e38620","user":{"login":"giampaolo","id":681260,"avatar_url":"https://avatars.githubusercontent.com/u/681260?v=3","gravatar_id":"","url":"https://api.github.com/users/giampaolo","html_url":"https://github.com/giampaolo","followers_url":"https://api.github.com/users/giampaolo/followers","following_url":"https://api.github.com/users/giampaolo/following{/other_user}","gists_url":"https://api.github.com/users/giampaolo/gists{/gist_id}","starred_url":"https://api.github.com/users/giampaolo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giampaolo/subscriptions","organizations_url":"https://api.github.com/users/giampaolo/orgs","repos_url":"https://api.github.com/users/giampaolo/repos","events_url":"https://api.github.com/users/giampaolo/events{/privacy}","received_events_url":"https://api.github.com/users/giampaolo/received_events","type":"User","site_admin":false},"body":"Please use `self.assertEqual` instead.","created_at":"2015-12-15T17:18:53Z","updated_at":"2015-12-15T17:18:53Z","html_url":"https://github.com/giampaolo/psutil/pull/719#discussion_r47667740","pull_request_url":"https://api.github.com/repos/giampaolo/psutil/pulls/719","_links":{"self":{"href":"https://api.github.com/repos/giampaolo/psutil/pulls/comments/47667740"},"html":{"href":"https://github.com/giampaolo/psutil/pull/719#discussion_r47667740"},"pull_request":{"href":"https://api.github.com/repos/giampaolo/psutil/pulls/719"}}},"pull_request":{"url":"https://api.github.com/repos/giampaolo/psutil/pulls/719","id":53730178,"html_url":"https://github.com/giampaolo/psutil/pull/719","diff_url":"https://github.com/giampaolo/psutil/pull/719.diff","patch_url":"https://github.com/giampaolo/psutil/pull/719.patch","issue_url":"https://api.github.com/repos/giampaolo/psutil/issues/719","number":719,"state":"open","locked":false,"title":"Add import-time tests for linux psutil","user":{"login":"sethp-jive","id":2934009,"avatar_url":"https://avatars.githubusercontent.com/u/2934009?v=3","gravatar_id":"","url":"https://api.github.com/users/sethp-jive","html_url":"https://github.com/sethp-jive","followers_url":"https://api.github.com/users/sethp-jive/followers","following_url":"https://api.github.com/users/sethp-jive/following{/other_user}","gists_url":"https://api.github.com/users/sethp-jive/gists{/gist_id}","starred_url":"https://api.github.com/users/sethp-jive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sethp-jive/subscriptions","organizations_url":"https://api.github.com/users/sethp-jive/orgs","repos_url":"https://api.github.com/users/sethp-jive/repos","events_url":"https://api.github.com/users/sethp-jive/events{/privacy}","received_events_url":"https://api.github.com/users/sethp-jive/received_events","type":"User","site_admin":false},"body":"Two new tests that validate:\r\n\r\n1) that psutil can be sucessfuly reload()'d on linux\r\n2) that a missing procfs doesn't prevent importing, or\r\n   correct functionality.","created_at":"2015-12-15T16:51:44Z","updated_at":"2015-12-15T17:18:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bc93456d81696c46209b96a03eb9ab16e66a782c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/giampaolo/psutil/pulls/719/commits","review_comments_url":"https://api.github.com/repos/giampaolo/psutil/pulls/719/comments","review_comment_url":"https://api.github.com/repos/giampaolo/psutil/pulls/comments{/number}","comments_url":"https://api.github.com/repos/giampaolo/psutil/issues/719/comments","statuses_url":"https://api.github.com/repos/giampaolo/psutil/statuses/3c26133cdc682833326f8b0a45c749f4a6e38620","head":{"label":"sethp-jive:tests/add-import-tests","ref":"tests/add-import-tests","sha":"3c26133cdc682833326f8b0a45c749f4a6e38620","user":{"login":"sethp-jive","id":2934009,"avatar_url":"https://avatars.githubusercontent.com/u/2934009?v=3","gravatar_id":"","url":"https://api.github.com/users/sethp-jive","html_url":"https://github.com/sethp-jive","followers_url":"https://api.github.com/users/sethp-jive/followers","following_url":"https://api.github.com/users/sethp-jive/following{/other_user}","gists_url":"https://api.github.com/users/sethp-jive/gists{/gist_id}","starred_url":"https://api.github.com/users/sethp-jive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sethp-jive/subscriptions","organizations_url":"https://api.github.com/users/sethp-jive/orgs","repos_url":"https://api.github.com/users/sethp-jive/repos","events_url":"https://api.github.com/users/sethp-jive/events{/privacy}","received_events_url":"https://api.github.com/users/sethp-jive/received_events","type":"User","site_admin":false},"repo":{"id":47359560,"name":"psutil","full_name":"sethp-jive/psutil","owner":{"login":"sethp-jive","id":2934009,"avatar_url":"https://avatars.githubusercontent.com/u/2934009?v=3","gravatar_id":"","url":"https://api.github.com/users/sethp-jive","html_url":"https://github.com/sethp-jive","followers_url":"https://api.github.com/users/sethp-jive/followers","following_url":"https://api.github.com/users/sethp-jive/following{/other_user}","gists_url":"https://api.github.com/users/sethp-jive/gists{/gist_id}","starred_url":"https://api.github.com/users/sethp-jive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sethp-jive/subscriptions","organizations_url":"https://api.github.com/users/sethp-jive/orgs","repos_url":"https://api.github.com/users/sethp-jive/repos","events_url":"https://api.github.com/users/sethp-jive/events{/privacy}","received_events_url":"https://api.github.com/users/sethp-jive/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sethp-jive/psutil","description":"A cross-platform process and system utilities module for Python","fork":true,"url":"https://api.github.com/repos/sethp-jive/psutil","forks_url":"https://api.github.com/repos/sethp-jive/psutil/forks","keys_url":"https://api.github.com/repos/sethp-jive/psutil/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sethp-jive/psutil/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sethp-jive/psutil/teams","hooks_url":"https://api.github.com/repos/sethp-jive/psutil/hooks","issue_events_url":"https://api.github.com/repos/sethp-jive/psutil/issues/events{/number}","events_url":"https://api.github.com/repos/sethp-jive/psutil/events","assignees_url":"https://api.github.com/repos/sethp-jive/psutil/assignees{/user}","branches_url":"https://api.github.com/repos/sethp-jive/psutil/branches{/branch}","tags_url":"https://api.github.com/repos/sethp-jive/psutil/tags","blobs_url":"https://api.github.com/repos/sethp-jive/psutil/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sethp-jive/psutil/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sethp-jive/psutil/git/refs{/sha}","trees_url":"https://api.github.com/repos/sethp-jive/psutil/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sethp-jive/psutil/statuses/{sha}","languages_url":"https://api.github.com/repos/sethp-jive/psutil/languages","stargazers_url":"https://api.github.com/repos/sethp-jive/psutil/stargazers","contributors_url":"https://api.github.com/repos/sethp-jive/psutil/contributors","subscribers_url":"https://api.github.com/repos/sethp-jive/psutil/subscribers","subscription_url":"https://api.github.com/repos/sethp-jive/psutil/subscription","commits_url":"https://api.github.com/repos/sethp-jive/psutil/commits{/sha}","git_commits_url":"https://api.github.com/repos/sethp-jive/psutil/git/commits{/sha}","comments_url":"https://api.github.com/repos/sethp-jive/psutil/comments{/number}","issue_comment_url":"https://api.github.com/repos/sethp-jive/psutil/issues/comments{/number}","contents_url":"https://api.github.com/repos/sethp-jive/psutil/contents/{+path}","compare_url":"https://api.github.com/repos/sethp-jive/psutil/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sethp-jive/psutil/merges","archive_url":"https://api.github.com/repos/sethp-jive/psutil/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sethp-jive/psutil/downloads","issues_url":"https://api.github.com/repos/sethp-jive/psutil/issues{/number}","pulls_url":"https://api.github.com/repos/sethp-jive/psutil/pulls{/number}","milestones_url":"https://api.github.com/repos/sethp-jive/psutil/milestones{/number}","notifications_url":"https://api.github.com/repos/sethp-jive/psutil/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sethp-jive/psutil/labels{/name}","releases_url":"https://api.github.com/repos/sethp-jive/psutil/releases{/id}","created_at":"2015-12-03T20:50:22Z","updated_at":"2015-12-03T20:50:26Z","pushed_at":"2015-12-15T16:56:13Z","git_url":"git://github.com/sethp-jive/psutil.git","ssh_url":"git@github.com:sethp-jive/psutil.git","clone_url":"https://github.com/sethp-jive/psutil.git","svn_url":"https://github.com/sethp-jive/psutil","homepage":null,"size":26473,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"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":"giampaolo:master","ref":"master","sha":"384a012afb2d66d217b46b471da134c938c51e1c","user":{"login":"giampaolo","id":681260,"avatar_url":"https://avatars.githubusercontent.com/u/681260?v=3","gravatar_id":"","url":"https://api.github.com/users/giampaolo","html_url":"https://github.com/giampaolo","followers_url":"https://api.github.com/users/giampaolo/followers","following_url":"https://api.github.com/users/giampaolo/following{/other_user}","gists_url":"https://api.github.com/users/giampaolo/gists{/gist_id}","starred_url":"https://api.github.com/users/giampaolo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giampaolo/subscriptions","organizations_url":"https://api.github.com/users/giampaolo/orgs","repos_url":"https://api.github.com/users/giampaolo/repos","events_url":"https://api.github.com/users/giampaolo/events{/privacy}","received_events_url":"https://api.github.com/users/giampaolo/received_events","type":"User","site_admin":false},"repo":{"id":20101515,"name":"psutil","full_name":"giampaolo/psutil","owner":{"login":"giampaolo","id":681260,"avatar_url":"https://avatars.githubusercontent.com/u/681260?v=3","gravatar_id":"","url":"https://api.github.com/users/giampaolo","html_url":"https://github.com/giampaolo","followers_url":"https://api.github.com/users/giampaolo/followers","following_url":"https://api.github.com/users/giampaolo/following{/other_user}","gists_url":"https://api.github.com/users/giampaolo/gists{/gist_id}","starred_url":"https://api.github.com/users/giampaolo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giampaolo/subscriptions","organizations_url":"https://api.github.com/users/giampaolo/orgs","repos_url":"https://api.github.com/users/giampaolo/repos","events_url":"https://api.github.com/users/giampaolo/events{/privacy}","received_events_url":"https://api.github.com/users/giampaolo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/giampaolo/psutil","description":"A cross-platform process and system utilities module for Python","fork":false,"url":"https://api.github.com/repos/giampaolo/psutil","forks_url":"https://api.github.com/repos/giampaolo/psutil/forks","keys_url":"https://api.github.com/repos/giampaolo/psutil/keys{/key_id}","collaborators_url":"https://api.github.com/repos/giampaolo/psutil/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/giampaolo/psutil/teams","hooks_url":"https://api.github.com/repos/giampaolo/psutil/hooks","issue_events_url":"https://api.github.com/repos/giampaolo/psutil/issues/events{/number}","events_url":"https://api.github.com/repos/giampaolo/psutil/events","assignees_url":"https://api.github.com/repos/giampaolo/psutil/assignees{/user}","branches_url":"https://api.github.com/repos/giampaolo/psutil/branches{/branch}","tags_url":"https://api.github.com/repos/giampaolo/psutil/tags","blobs_url":"https://api.github.com/repos/giampaolo/psutil/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/giampaolo/psutil/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/giampaolo/psutil/git/refs{/sha}","trees_url":"https://api.github.com/repos/giampaolo/psutil/git/trees{/sha}","statuses_url":"https://api.github.com/repos/giampaolo/psutil/statuses/{sha}","languages_url":"https://api.github.com/repos/giampaolo/psutil/languages","stargazers_url":"https://api.github.com/repos/giampaolo/psutil/stargazers","contributors_url":"https://api.github.com/repos/giampaolo/psutil/contributors","subscribers_url":"https://api.github.com/repos/giampaolo/psutil/subscribers","subscription_url":"https://api.github.com/repos/giampaolo/psutil/subscription","commits_url":"https://api.github.com/repos/giampaolo/psutil/commits{/sha}","git_commits_url":"https://api.github.com/repos/giampaolo/psutil/git/commits{/sha}","comments_url":"https://api.github.com/repos/giampaolo/psutil/comments{/number}","issue_comment_url":"https://api.github.com/repos/giampaolo/psutil/issues/comments{/number}","contents_url":"https://api.github.com/repos/giampaolo/psutil/contents/{+path}","compare_url":"https://api.github.com/repos/giampaolo/psutil/compare/{base}...{head}","merges_url":"https://api.github.com/repos/giampaolo/psutil/merges","archive_url":"https://api.github.com/repos/giampaolo/psutil/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/giampaolo/psutil/downloads","issues_url":"https://api.github.com/repos/giampaolo/psutil/issues{/number}","pulls_url":"https://api.github.com/repos/giampaolo/psutil/pulls{/number}","milestones_url":"https://api.github.com/repos/giampaolo/psutil/milestones{/number}","notifications_url":"https://api.github.com/repos/giampaolo/psutil/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/giampaolo/psutil/labels{/name}","releases_url":"https://api.github.com/repos/giampaolo/psutil/releases{/id}","created_at":"2014-05-23T14:01:48Z","updated_at":"2015-12-15T09:09:02Z","pushed_at":"2015-12-15T17:13:29Z","git_url":"git://github.com/giampaolo/psutil.git","ssh_url":"git@github.com:giampaolo/psutil.git","clone_url":"https://github.com/giampaolo/psutil.git","svn_url":"https://github.com/giampaolo/psutil","homepage":null,"size":26629,"stargazers_count":1210,"watchers_count":1210,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":192,"mirror_url":null,"open_issues_count":77,"forks":192,"open_issues":77,"watchers":1210,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/giampaolo/psutil/pulls/719"},"html":{"href":"https://github.com/giampaolo/psutil/pull/719"},"issue":{"href":"https://api.github.com/repos/giampaolo/psutil/issues/719"},"comments":{"href":"https://api.github.com/repos/giampaolo/psutil/issues/719/comments"},"review_comments":{"href":"https://api.github.com/repos/giampaolo/psutil/pulls/719/comments"},"review_comment":{"href":"https://api.github.com/repos/giampaolo/psutil/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/giampaolo/psutil/pulls/719/commits"},"statuses":{"href":"https://api.github.com/repos/giampaolo/psutil/statuses/3c26133cdc682833326f8b0a45c749f4a6e38620"}}}}