From 4b24143e126c133df1289b2f032a1eaacf59e5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20De=20Keersmaeker?= <francois.dekeersmaeker@uclouvain.be> Date: Wed, 11 Dec 2024 10:34:22 +0100 Subject: [PATCH] Unit tests: unittest -> pytest --- test/test.py | 56 ------------------------------------------ test/test_translate.py | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 56 deletions(-) delete mode 100644 test/test.py create mode 100644 test/test_translate.py diff --git a/test/test.py b/test/test.py deleted file mode 100644 index e8877af..0000000 --- a/test/test.py +++ /dev/null @@ -1,56 +0,0 @@ -import os -from pathlib import Path -import unittest -import profile_translator_blocklist - -# Paths -self_name = os.path.basename(__file__) -self_path = Path(os.path.abspath(__file__)) -self_dir = self_path.parents[0] - - -class TestProfileTranslator(unittest.TestCase): - """ - Test class for the package `profile-translator`. - """ - - - def test_translate_policy(self): - """ - Test the function `translate_policy` from the package `profile-translator`. - """ - device = { - "name": "sample-device", - "ipv4": "192.168.1.2" - } - policy_dict = { - "protocols": { - "dns": { - "domain-name": "example.com", - "qtype": "A" - }, - "udp": { - "dst-port": 53 - }, - "ipv4": { - "src": "self", - "dst": "192.168.1.1" - } - }, - "bidirectional": True - } - - profile_translator_blocklist.translate_policy(device, policy_dict) - - - def test_translate_profile(self): - """ - Test the function `translate_profile` from the package `profile-translator`. - """ - sample_profile = os.path.join(self_dir, 'profile.yaml') - profile_translator_blocklist.translate_profile(sample_profile) - - -### MAIN ### -if __name__ == '__main__': - unittest.main() diff --git a/test/test_translate.py b/test/test_translate.py new file mode 100644 index 0000000..e774360 --- /dev/null +++ b/test/test_translate.py @@ -0,0 +1,46 @@ +import os +from pathlib import Path +from profile_translator_blocklist import translate_policy, translate_profile + +# Paths +self_name = os.path.basename(__file__) +self_path = Path(os.path.abspath(__file__)) +self_dir = self_path.parents[0] + + +### TEST FUNCTIONS ### + +def test_translate_policy() -> None: + """ + Test the function `translate_policy` from the package `profile-translator`. + """ + device = { + "name": "sample-device", + "ipv4": "192.168.1.2" + } + policy_dict = { + "protocols": { + "dns": { + "domain-name": "example.com", + "qtype": "A" + }, + "udp": { + "dst-port": 53 + }, + "ipv4": { + "src": "self", + "dst": "192.168.1.1" + } + }, + "bidirectional": True + } + + translate_policy(device, policy_dict) + + +def test_translate_profile() -> None: + """ + Test the function `translate_profile` from the package `profile-translator`. + """ + sample_profile = os.path.join(self_dir, 'profile.yaml') + translate_profile(sample_profile) -- GitLab