tests: add unit tests for AugurUUID and subclasses#3749
tests: add unit tests for AugurUUID and subclasses#3749Inengs wants to merge 4 commits intoaugurlabs:mainfrom
Conversation
Signed-off-by: Inengs <inengiyeemmanuel@gmail.com>
| # this checks whether a brand new AugurUUID object starts as 16 zero bytes | ||
| def test_augur_uuid_initializes_with_16_zero_bytes(): | ||
| uid = AugurUUID() | ||
| assert len(uid.bytes) == 16 |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| def test_augur_uuid_initializes_with_16_zero_bytes(): | ||
| uid = AugurUUID() | ||
| assert len(uid.bytes) == 16 | ||
| assert all(b == 0 for b in uid.bytes) |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| # checks that githubUUID sets its platform number to 1 | ||
| def test_github_uuid_platform_is_1(): | ||
| uid = GithubUUID() | ||
| assert uid["platform"] == 1 |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| # checks that gitlabUUID sets its platform number to 2 | ||
| def test_gitlab_uuid_platform_is_2(): | ||
| uid = GitlabUUID() | ||
| assert uid["platform"] == 2 |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
|
|
||
| def test_unresolvable_uuid_platform_is_0(): | ||
| uid = UnresolvableUUID() | ||
| assert uid["platform"] == 0 |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| def test_gitlab_uuid_set_user(): | ||
| uid = GitlabUUID() | ||
| uid["user"] = 99999 | ||
| assert uid["user"] == 99999 |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| uid = GithubUUID() | ||
| uid["user"] = 15 | ||
| result = uid.to_UUID() | ||
| assert isinstance(result, uuid.UUID) |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| uid2 = GithubUUID() | ||
| uid1["user"] = 100 | ||
| uid2["user"] = 100 | ||
| assert uid1 == uid2 |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| uid2 = GithubUUID() | ||
| uid1["user"] = 100 | ||
| uid2["user"] = 200 | ||
| assert uid1 != uid2 |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| gitlab_uid = GitlabUUID() | ||
| github_uid["user"] = 100 | ||
| gitlab_uid["user"] = 100 | ||
| assert github_uid != gitlab_uid No newline at end of file |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
|
yeah ignore bandit there Can you add this test folder/file to the pytest section of |
|
Alright I will do that as soon as possible, thank you |
Signed-off-by: Inengs <inengiyeemmanuel@gmail.com>
|
Hi, I have added the test file to the pyproject.toml please let me know if there is anything else needed, thank you! |
MoralCode
left a comment
There was a problem hiding this comment.
Id like to see fewer test cases that just assert that each type's identifier is correct and more tests that exercise the various edge cases and code branches within the logic of AugurUUID (even if you use a GitHubUUID instance for doing the test)
| def test_gitlab_uuid_set_user(): | ||
| uid = GitlabUUID() | ||
| uid["user"] = 99999 | ||
| assert uid["user"] == 99999 |
There was a problem hiding this comment.
this test is probably redundant with other tests
|
|
||
| def test_unresolvable_uuid_platform_is_0(): | ||
| uid = UnresolvableUUID() | ||
| assert uid["platform"] == 0 |
There was a problem hiding this comment.
this test is pretty trivial and therefore not really that helpful
|
Alright, I will make those changes as soon as possible.. |
Signed-off-by: Inengs <inengiyeemmanuel@gmail.com>
|
Hi, I have updated the tests based on your feedback please let me know if there is anything else needed, thank you! |
| # checks the maximum value that fits into user field | ||
| def test_user_field_max_value(): | ||
| uid = GithubUUID() | ||
| uid["user"] = 4294967295 | ||
| assert uid["user"] == 4294967295 | ||
|
|
||
| # checks the minimum boundary | ||
| def test_user_field_zero_value(): | ||
| uid = GithubUUID() | ||
| uid["user"] = 0 | ||
| assert uid["user"] == 0 | ||
|
|
||
| def test_len_returns_16(): | ||
| uid = AugurUUID() | ||
| assert len(uid) == 16 |
There was a problem hiding this comment.
these tests arent really that helpful
| def test_iteration_over_bytes(): | ||
| uid = AugurUUID() | ||
| bytes_list = list(uid) | ||
|
|
||
| assert len(bytes_list) == 16 |
There was a problem hiding this comment.
this is effectively the same as the len() test
Signed-off-by: Inengiye Emmanuel <inengiyeemmanuel@gmail.com>
|
Hi, I have removed the redundant tests. please let me know if there is anything needed to add, thank you! |
Description
Tests cover:
This PR fixes #3744
Notes for Reviewers
Signed commits