-
Notifications
You must be signed in to change notification settings - Fork 232
Fixing anti-patterns #1039
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
Fixing anti-patterns #1039
Changes from all commits
305f4e5
79c875b
10ad3b3
1e4c141
111d17d
de55e9a
3474153
3fd10c8
53bb89f
af9addf
4fa6d99
ac46da0
bfaecf9
823457c
170cf1c
e446320
b333442
1d78412
7cbe0e6
806f662
c5bac19
86d84e2
5a914a0
b220dca
e4ee0b3
1967e7d
cdb99b2
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 |
|---|---|---|
|
|
@@ -20,8 +20,15 @@ short summary of the most important parts: | |
| * Always use `self` for the first argument to instance methods. | ||
| * Always use `cls` for the first argument to class methods. | ||
| * Use one leading underscore only for non-public methods and instance variables, | ||
| such as `_data`. | ||
| such as `_data`. Do not activate name mangling with `__` unless necessary. | ||
| * If there is a pair of `get_x` and `set_x` methods, they should instead be a | ||
| proper property, which is easy to do with the built-in `@property` decorator. | ||
| * Constants should be `CAPITALIZED_SNAKE_CASE`. | ||
| * When importing a function, try to avoid renaming it with `import as` because | ||
|
Contributor
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. It's my previous experience, and can be fixed and document. for example, |
||
| it introduces cognitive overhead to track yet another name. | ||
| * When deriving another module’s class (such as `unittest.TestCase`), reuse the | ||
|
Contributor
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. As my explanation in overall comments, |
||
| class name to avoid confusion, such as `LisaTestCase`, instead of introducing | ||
| a different connotation like `TestSuite`. | ||
|
|
||
| When in doubt, adhere to existing conventions, or check the style guide. | ||
|
|
||
|
|
@@ -252,6 +259,18 @@ Python world. If you make it through even some of these guides, you will be well | |
| on your way to being a “Pythonista” (a Python developer) writing “Pythonic” | ||
| (canonically correct Python) code left and right. | ||
|
|
||
| ### Async IO | ||
|
|
||
| With Python 3.4, the Async IO pattern found in languages such as C# and Go is | ||
|
andyleejordan marked this conversation as resolved.
|
||
| available through the keywords `async` and `await`, along with the Python module | ||
| `asyncio`. Please read [Async IO in Python: A Complete | ||
| Walkthrough](https://realpython.com/async-io-python/) to understand at a high | ||
| level how asynchronous programming works. As of Python 3.7, One major “gotcha” | ||
| is that `asyncio.run(...)` should be used [exactly once in | ||
| `main`](https://docs.python.org/3/library/asyncio-task.html), it starts the | ||
| event loop. Everything else should be a coroutine or task which the event loop | ||
| schedules. | ||
|
|
||
| ## Future Sections | ||
|
|
||
| Just a collection of reminders for the author to expand on later. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| from lisa import TestCaseMetadata, TestSuite, TestSuiteMetadata | ||
| from lisa import LisaTestCase, LisaTestCaseMetadata, LisaTestMetadata | ||
| from lisa.operating_system import Linux | ||
| from lisa.tools import Echo, Uname | ||
|
|
||
|
|
||
| @TestSuiteMetadata( | ||
| @LisaTestCaseMetadata( | ||
|
Contributor
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. Keep class -> suite, and method -> case. See my explanation in overall comments, we have different concept on them than Python ut. We're not write UT, so the concept of suite and case are heavier than Python UT. |
||
| area="demo", | ||
| category="simple", | ||
| description=""" | ||
|
|
@@ -12,8 +12,8 @@ | |
| """, | ||
| tags=["demo"], | ||
| ) | ||
| class HelloWorld(TestSuite): | ||
| @TestCaseMetadata( | ||
| class HelloWorld(LisaTestCase): | ||
| @LisaTestMetadata( | ||
|
Contributor
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. The |
||
| description=""" | ||
| this test case use default node to | ||
| 1. get system info | ||
|
|
@@ -43,7 +43,7 @@ def hello(self) -> None: | |
| self.assertEqual("", result.stderr) | ||
| self.assertEqual(0, result.exit_code) | ||
|
|
||
| @TestCaseMetadata( | ||
| @LisaTestMetadata( | ||
| description=""" | ||
| demonstrate a simple way to run command in one line. | ||
| """, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from lisa.testsuite import TestCaseMetadata, TestSuite, TestSuiteMetadata | ||
| from lisa.testsuite import LisaTestCase, LisaTestCaseMetadata, LisaTestMetadata | ||
| from lisa.util.logger import init_loggger | ||
|
|
||
| __all__ = [ | ||
| "TestSuiteMetadata", | ||
| "TestCaseMetadata", | ||
| "TestSuite", | ||
| "LisaTestCase", | ||
|
Contributor
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. I need some guidances what kind of things worth to have a shortcut in |
||
| "LisaTestCaseMetadata", | ||
| "LisaTestMetadata", | ||
| ] | ||
|
|
||
|
|
||
|
|
||
This file was deleted.
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.
as pep8,
_nameuses to mark "subclass API".__is for private in this case.