-
Notifications
You must be signed in to change notification settings - Fork 12
Add tests #25
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
Add tests #25
Conversation
77fae4e to
4318162
Compare
- Check output when no argument is provided; - Check if stdin is ignored by default; - Check if stdin is ignored if file is provided; - Check how many arguments a utility accepts; - Check how word splitting works on multiple arguments; - Check if newline is present; and - How it treats the argument '-'.
0cc3cbe to
2e92192
Compare
ArrayBolt3
left a comment
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.
Tests pass both as-is and with the couple of functional changes suggested.
| i = 0 | ||
| self.tmpdir = tempfile.mkdtemp() | ||
| while i < 6: | ||
| self.tmpfiles_list.append(os.path.join(self.tmpdir, str(i))) | ||
| with open(self.tmpfiles_list[i], "w", encoding="utf-8") as file: | ||
| if i == 0: | ||
| file.write("") | ||
| elif i == 1: | ||
| file.write("".join(contents)) | ||
| elif i == 2: | ||
| file.write("".join(contents) + "\n") | ||
| elif i == 3: | ||
| file.write(self.text_dirty) | ||
| elif i in [4, 5]: | ||
| pass | ||
| file.flush() | ||
| file.close() | ||
| i += 1 |
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.
| i = 0 | |
| self.tmpdir = tempfile.mkdtemp() | |
| while i < 6: | |
| self.tmpfiles_list.append(os.path.join(self.tmpdir, str(i))) | |
| with open(self.tmpfiles_list[i], "w", encoding="utf-8") as file: | |
| if i == 0: | |
| file.write("") | |
| elif i == 1: | |
| file.write("".join(contents)) | |
| elif i == 2: | |
| file.write("".join(contents) + "\n") | |
| elif i == 3: | |
| file.write(self.text_dirty) | |
| elif i in [4, 5]: | |
| pass | |
| file.flush() | |
| file.close() | |
| i += 1 | |
| self.tmpdir = tempfile.mkdtemp() | |
| for i in range(0, 6): | |
| self.tmpfiles_list.append(os.path.join(self.tmpdir, str(i))) | |
| with open(self.tmpfiles_list[i], "w", encoding="utf-8") as file: | |
| if i == 0: | |
| file.write("") | |
| elif i == 1: | |
| file.write("".join(contents)) | |
| elif i == 2: | |
| file.write("".join(contents) + "\n") | |
| elif i == 3: | |
| file.write(self.text_dirty) | |
| elif i in [4, 5]: | |
| pass | |
| file.flush() | |
| file.close() |
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.
Github browser diff is bad on this case. Is the change while to for and removal of the individual i var assignments?
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 the change while to for and removal of the individual i var assignments?
Yes.
Github browser diff is bad on this case.
Yeah... not sure why it didn't render this very well this time.
| shutil.rmtree(self.tmpdir) | ||
|
|
||
| def _del_module(self) -> None: | ||
| for module in ["stdisplay." + self.module]: # type: ignore # pylint: disable=no-member |
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.
It might be useful to document that self.module is going to be defined in the individual tests themselves.
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.
Done.
| def _get_file(self, file: str) -> str: | ||
| """ | ||
| Helper function get contents of a file. | ||
| """ | ||
| with open(file, mode="r", encoding="utf-8") as fileobj: | ||
| text = fileobj.read() | ||
| return text |
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.
Could Path.read_text() be used instead of a custom helper function for this?
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.
Makes sense. Done.
| import stdisplay.tests | ||
|
|
||
|
|
||
| class TestSTCat(stdisplay.tests.TestSTBase): |
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.
| class TestSTCat(stdisplay.tests.TestSTBase): | |
| class TestSTCatn(stdisplay.tests.TestSTBase): |
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.
Fixed.
| class TestSTPrint(stdisplay.tests.TestSTBase): | ||
| """ | ||
| Test stprint | ||
| Test stecho. |
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.
| Test stecho. | |
| Test stprint. |
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.
Done.
| "", | ||
| self._get_file(file=self.tmpfiles["fill"]), | ||
| ) | ||
| # Empty stdin when writing to file and file sanitization. |
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.
| # Empty stdin when writing to file and file sanitization. | |
| # Empty stdout when writing to file and file sanitization. |
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.
Fixed.
| self.text_dirty_sanitized, | ||
| self._get_file(file=self.tmpfiles["fill"]), | ||
| ) | ||
| # Empty stdin when writing to multiple files and its sanitization. |
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.
| # Empty stdin when writing to multiple files and its sanitization. | |
| # Empty stdout when writing to multiple files and its sanitization. |
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.
Fixed.
Changes
Add tests for safe terminal utilities.
Mandatory Checklist
Terms of Service, Privacy Policy, Cookie Policy, E-Sign Consent, DMCA, Imprint
Optional Checklist
The following items are optional but might be requested in certain cases.
Fixes: