-
Notifications
You must be signed in to change notification settings - Fork 39
further unit test speedups and cleanups #9226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ | |
| # You should have received a copy of the GNU Lesser General Public License | ||
| # along with Cockpit; If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| import fnmatch | ||
| import json | ||
| import shutil | ||
| import tempfile | ||
|
|
@@ -88,21 +87,15 @@ def test_cache(self) -> None: | |
| self.assertEqual(count, 1) | ||
|
|
||
| def test_log(self) -> None: | ||
| self.api.get("/test/user") | ||
| self.api.cache.mark(time.time() + 1) | ||
| self.api.get("/test/user") | ||
|
|
||
| expect = ( | ||
| '127.0.0.8:9898 - - * "GET /test/user HTTP/1.1" 200 -\n' | ||
| '127.0.0.8:9898 - - * "GET /test/user HTTP/1.1" 304 -\n' | ||
| ) | ||
|
|
||
| with open(self.api.log.path, "r") as f: | ||
| data = f.read() | ||
|
|
||
| match = fnmatch.fnmatch(data, expect) | ||
| if not match: | ||
| self.fail(f"'{data}' did not match '{expect}'") | ||
| with self.assertLogs('lib.github', level='DEBUG') as logs: | ||
| self.api.get("/test/user") | ||
| self.api.cache.mark(time.time() + 1) | ||
| self.api.get("/test/user") | ||
|
|
||
| self.assertEqual(logs.output, [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation? Doesn't this need to be under the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no. it doesn't. and maybe even shouldn't. the inside the compare that also with the with self.assertRaises(ValueError) as cm:
do_something()
self.assertEqual(str(cm.exception), "invalid value")
self.assertEqual(cm.exception.args, ("invalid value",))because you can't do the compare until after the exception, but the exception is going to shoot you out of the block.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha, thanks! I was mostly suprised that "logs" is even available outside of the "with". TIL! |
||
| 'DEBUG:lib.github:127.0.0.8:9898 GET /test/user → 200', | ||
| 'DEBUG:lib.github:127.0.0.8:9898 GET /test/user → 304', | ||
| ]) | ||
|
|
||
| def test_issues_since(self) -> None: | ||
| issues = self.api.issues(since=1499838499) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "oauth token" the same as "github token" in this context? Why does this message say "oauth token"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this is saying "no oauth_token assignment in the config file", got it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya this is specifically about the case where (as a final fallback option) we raid the gh cli config and look for an existing token but fail to find it.