Sorry, something went wrong.
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you for your first CPython PR! I hope this will be followed by many more.
See a couple of comments below.
Sorry, something went wrong.
| thread.exc = None | ||
|
|
||
| def test_multithread_modify_file_noerror(self): | ||
| import traceback |
There was a problem hiding this comment.
I believe PEP-8 asks for imports to be at module scope
Sorry, something went wrong.
There was a problem hiding this comment.
Hi @iritkatriel
Thank you for your feedback and I'll rewrite it to support pep8.
Incidentally, pep-8 point out where I have not changed this time.
Should I also refactor the following?
Sorry, something went wrong.
| self.assertTrue(_) | ||
| self.assertEqual(1, len(linecache.cache.keys())) | ||
|
|
||
| with support.swap_attr(os, 'stat', raise_oserror): |
There was a problem hiding this comment.
The fact that os.stat is used in checkcache is an implementation detail, not a part of that's function's external API, so I don't think the unit test should depend on that.
I would write this as a black-box test. And also test that the cache clearing is selective. Note that there are two cases in checkcache() where the cache is popped: OSError from stat, or size/timestamp don't match.
So, create three files f1, f2, f3 and load them into the cache. Then delete f1, modify f2 and call checkcache. Ensure that the cache entries for f1 and f2 were removed from the cache but the entries for f3 are still there.
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you for your feedback.
As you said, other tests are written in such a way that they do not depend on the internal implementation.
I will try to write them in a black box as you suggested, so I would appreciate it if you could take look again !!
Sorry, something went wrong.
There was a problem hiding this comment.
I write a black box test, and would be happy if you could check it out.
Sorry, something went wrong.
| _ = linecache.getlines(source_name) | ||
| self.assertEqual(1, len(linecache.cache.keys())) | ||
|
|
||
| with support.swap_attr(os, 'stat', raise_oserror): |
There was a problem hiding this comment.
As above - delete/modify the file instead of mocking os.stat.
Sorry, something went wrong.
There was a problem hiding this comment.
As shown above, I write delete/modify test.
Sorry, something went wrong.
| self.assertEqual(lines3, []) | ||
| self.assertEqual(linecache.getlines(FILENAME), lines) | ||
|
|
||
| def test_oserror(self): |
There was a problem hiding this comment.
This is better. Now let's see how it should be organized. I have several comments:
You could create a new test class , say class LineCacheInvalidationTests(unittest.TestCase):
Put the initialization code (what you called _oserror_helper) in this class's setUp.
Then add test functions for each test case.
Sorry, something went wrong.
| for t in threads: | ||
| t.start() | ||
| for t in threads: | ||
| t.join() |
There was a problem hiding this comment.
Is there a reason why you don't do
?
Sorry, something went wrong.
There was a problem hiding this comment.
Nothing, sorry.
So I fixed it to your feedback.
Sorry, something went wrong.
| threading.Thread(target=modify_file) | ||
| for i in range(100) | ||
| ] | ||
| try: |
There was a problem hiding this comment.
Which exceptions are you trying to ignore here?
Sorry, something went wrong.
There was a problem hiding this comment.
Nothing, sorry. I removed try.
Sorry, something went wrong.
| def test_checkcache_with_no_parameters(self): | ||
| self.assertEqual(3, len(linecache.cache.keys())) | ||
| linecache.checkcache() | ||
| self.assertTrue([self.unchange_file] == list(linecache.cache.keys())) |
There was a problem hiding this comment.
assertEqual
Sorry, something went wrong.
| self.assertEqual(3, len(linecache.cache.keys())) | ||
| linecache.checkcache(self.deleted_file) | ||
| self.assertTrue(2 == len(linecache.cache.keys()) and | ||
| self.deleted_file not in linecache.cache.keys()) |
There was a problem hiding this comment.
Break this up into assertEqual and assertNotIn. See the assert methods here: https://docs.python.org/3/library/unittest.html
That way we get better error messages in the output when the assertion fails.
Sorry, something went wrong.
There was a problem hiding this comment.
This is a new thing I wanted to show you - I made a couple of suggested edits. You can click to accept them (and then you don't need to make a new commit). They will be committed, and then you need to pull the changes into your local repo so that you are in sync ("git pull" should do it).
Sorry, something went wrong.
|
The rebase doesn't look right - the PR should not be showing so many changed files. |
Sorry, something went wrong.
|
🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit ac550ef 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
Sorry, something went wrong.
|
Thanks @uniocto for the PR, and @iritkatriel for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.9. |
Sorry, something went wrong.
|
Sorry, @uniocto and @iritkatriel, I could not cleanly backport this to 3.9 due to a conflict. |
Sorry, something went wrong.
|
GH-26208 is a backport of this pull request to the 3.10 branch. |
Sorry, something went wrong.
|
GH-26211 is a backport of this pull request to the 3.9 branch. |
Sorry, something went wrong.
https://bugs.python.org/issue25872
https://bugs.python.org/issue25872