-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add assertion, handy shortcut for example Pytest's test (#30)
* Add assertion, handy shortcut for example Pytest's test * Black reformat
- Loading branch information
Showing
7 changed files
with
106 additions
and
1 deletion.
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
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,25 @@ | ||
from scapy_helper import PacketAssert | ||
|
||
|
||
def assert_hex_equal(first, second, message="Hex values are not equal"): | ||
PacketAssert.assertHexEqual(first, second, message) | ||
|
||
|
||
def assert_hex_not_equal(first, second, message="Hex values are equal"): | ||
PacketAssert.assertHexNotEqual(first, second, message) | ||
|
||
|
||
def assert_hex_len_equal(first, second, message="Hex len is equal"): | ||
PacketAssert.assertHexLenEqual(first, second, message) | ||
|
||
|
||
def assert_hex_len_not_equal(first, second, message="Hex len is not equal"): | ||
PacketAssert.assertHexLenNotEqual(first, second, message) | ||
|
||
|
||
def assert_bytes_equal(first, second, message="Bytes values are not equal"): | ||
PacketAssert.assertBytesEqual(first, second, message) | ||
|
||
|
||
def assert_bytes_not_equal(first, second, message="Bytes values are eqaul"): | ||
PacketAssert.assertBytesNotEqual(first, second, message) |
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
Empty file.
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,53 @@ | ||
from unittest import TestCase | ||
|
||
from scapy_helper.test_case_extensions.pytest_assert import ( | ||
assert_hex_equal, | ||
assert_hex_not_equal, | ||
assert_hex_len_equal, | ||
assert_hex_len_not_equal, | ||
) | ||
|
||
DEFAULT_HEX = ( | ||
"ff ff ff ff ff ff 00 00 00 00 00 00 08 00 45 00 00 " | ||
"28 00 01 00 00 40 06 7c cd 7f 00 00 01 7f 00 00 01 " | ||
"00 14 00 50 00 00 00 00 00 00 00 00 50 02 20 00 91 " | ||
"7c 00 00" | ||
) | ||
DIFFERENT_HEX = ( | ||
"00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00 " | ||
"00 28 00 01 00 00 40 06 7c cd 7f 00 00 01 7f 00 " | ||
"00 01 00 14 00 50 00 00 00 00 00 00 00 00 50 02 " | ||
"20 00 91 7c 00 00" | ||
) | ||
|
||
|
||
class TestPytestAssert(TestCase): | ||
def test_assert_hex_equal(self): | ||
assert_hex_equal(DEFAULT_HEX, DEFAULT_HEX) | ||
|
||
with self.assertRaises(AssertionError): | ||
assert_hex_equal(DEFAULT_HEX, DIFFERENT_HEX) | ||
|
||
def test_assert_hex_not_equal(self): | ||
assert_hex_not_equal(DEFAULT_HEX, DIFFERENT_HEX) | ||
|
||
with self.assertRaises(AssertionError): | ||
assert_hex_not_equal(DEFAULT_HEX, DEFAULT_HEX) | ||
|
||
def test_assert_hex_len_equal(self): | ||
assert_hex_len_equal(DEFAULT_HEX, DEFAULT_HEX) | ||
|
||
with self.assertRaises(AssertionError): | ||
assert_hex_len_equal(DEFAULT_HEX, DEFAULT_HEX[: len(DEFAULT_HEX) - 2]) | ||
|
||
def test_assert_hex_len_not_equal(self): | ||
assert_hex_len_not_equal(DEFAULT_HEX, DEFAULT_HEX[: len(DEFAULT_HEX) - 2]) | ||
|
||
with self.assertRaises(AssertionError): | ||
assert_hex_len_not_equal(DEFAULT_HEX, DEFAULT_HEX) | ||
|
||
# def test_assert_bytes_equal(self): | ||
# self.fail() | ||
# | ||
# def test_assert_bytes_not_equal(self): | ||
# self.fail() |