-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since Python 3.10, repr() of Enum shows members in definition order so it's hard to rely on this in doctests while testing with other Python versions. Move those tests as unit tests and compare values instead of repr().
- Loading branch information
Showing
2 changed files
with
74 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from pgactivity.types import Flag | ||
|
||
|
||
def test_flag(): | ||
f = Flag(3) | ||
assert f == Flag.APPNAME | Flag.DATABASE | ||
assert f | Flag.CLIENT == Flag.CLIENT | Flag.APPNAME | Flag.DATABASE | ||
f ^= Flag.APPNAME | ||
assert f == Flag.DATABASE | ||
|
||
|
||
def test_flag_from_options(): | ||
options = { | ||
"noappname": False, | ||
"noclient": False, | ||
"nocpu": False, | ||
"nodb": False, | ||
"nomem": False, | ||
"nopid": False, | ||
"noread": False, | ||
"notime": False, | ||
"nouser": False, | ||
"nowait": False, | ||
"nowrite": False, | ||
} | ||
flag = Flag.from_options(is_local=True, **options) | ||
assert ( | ||
flag | ||
== Flag.PID | ||
| Flag.IOWAIT | ||
| Flag.MODE | ||
| Flag.TYPE | ||
| Flag.RELATION | ||
| Flag.WAIT | ||
| Flag.TIME | ||
| Flag.WRITE | ||
| Flag.READ | ||
| Flag.MEM | ||
| Flag.CPU | ||
| Flag.USER | ||
| Flag.CLIENT | ||
| Flag.APPNAME | ||
| Flag.DATABASE | ||
) | ||
flag = Flag.from_options(is_local=False, **options) | ||
assert ( | ||
flag | ||
== Flag.PID | ||
| Flag.MODE | ||
| Flag.TYPE | ||
| Flag.RELATION | ||
| Flag.WAIT | ||
| Flag.TIME | ||
| Flag.USER | ||
| Flag.CLIENT | ||
| Flag.APPNAME | ||
| Flag.DATABASE | ||
) | ||
options["nodb"] = True | ||
options["notime"] = True | ||
options["nopid"] = True | ||
flag = Flag.from_options(is_local=False, **options) | ||
assert ( | ||
flag | ||
== Flag.MODE | ||
| Flag.TYPE | ||
| Flag.RELATION | ||
| Flag.WAIT | ||
| Flag.USER | ||
| Flag.CLIENT | ||
| Flag.APPNAME | ||
) |