Skip to content

Commit

Permalink
Testing logging.h, Some errors need to be fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ashariff-11 committed Oct 31, 2024
1 parent 77ad094 commit bec8772
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lang/python/nanobind_core/src/modules/module_logging_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,23 @@
#include <modules/module_logging_config.h>
#include <ecal/config/logging.h>



void AddLoggingConfigStructToModule(nanobind::module_& m)
{
nanobind::enum_<eCAL_Logging_eLogLevel>(m, "eCAL_Logging_Filter")
.value("log_level_none", log_level_none)
.value("log_level_all", log_level_all)
.value("log_level_info", log_level_info)
.value("log_level_warning", log_level_warning)
.value("log_level_error", log_level_error)
.value("log_level_fatal", log_level_fatal)
.value("log_filter_default", 15) //Line has to be discussed
.value("log_level_debug1", log_level_debug1)
.value("log_level_debug2", log_level_debug2)
.value("log_level_debug3", log_level_debug3)
.value("log_level_debug4", log_level_debug4);

// Bind the Console::Configuration structure
nanobind::class_<eCAL::Logging::Sinks::Console::Configuration>(m, "ConsoleConfiguration")
.def(nanobind::init<>()) // Constructor binding
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import unittest
import nanobind_core as ecal

class TestConsoleConfiguration(unittest.TestCase):

def setUp(self):
"""Create an instance of ConsoleConfiguration before each test."""
self.console_config = ecal.ConsoleConfiguration()

def test_default_values(self):
"""Test the default values of the ConsoleConfiguration."""
self.assertTrue(self.console_config.enable)
self.assertEqual(self.console_config.filter_log_con, ecal.eCAL_Logging_Filter.log_filter_default)

def test_enable_property(self):
"""Test setting the enable property."""
self.console_config.enable = False
self.assertFalse(self.console_config.enable)

self.console_config.enable = True
self.assertTrue(self.console_config.enable)

def test_filter_log_con_property(self):
"""Test setting the filter_log_con property."""
self.console_config.filter_log_con = ecal.eCAL_Logging_Filter.log_level_info
self.assertEqual(self.console_config.filter_log_con, ecal.eCAL_Logging_Filter.log_level_info)


class TestFileConfiguration(unittest.TestCase):

def setUp(self):
"""Create an instance of FileConfiguration before each test."""
self.file_config = ecal.FileConfiguration()

def test_default_values(self):
"""Test the default values of the FileConfiguration."""
self.assertFalse(self.file_config.enable)
self.assertEqual(self.file_config.path, "")
self.assertEqual(self.file_config.filter_log_file, ecal.eCAL_Logging_Filter.log_level_none)

def test_enable_property(self):
"""Test setting the enable property."""
self.file_config.enable = True
self.assertTrue(self.file_config.enable)

self.file_config.enable = False
self.assertFalse(self.file_config.enable)

def test_path_property(self):
"""Test setting the path property."""
self.file_config.path = "/tmp/my_log_file.log"
self.assertEqual(self.file_config.path, "/tmp/my_log_file.log")

def test_filter_log_file_property(self):
"""Test setting the filter_log_file property."""
self.file_config.filter_log_file = ecal.eCAL_Logging_Filter.log_level_error
self.assertEqual(self.file_config.filter_log_file, ecal.eCAL_Logging_Filter.log_level_error)


class TestUDPConfiguration(unittest.TestCase):

def setUp(self):
"""Create an instance of UDPConfiguration before each test."""
self.udp_config = ecal.UDPConfiguration()

def test_default_values(self):
"""Test the default values of the UDPConfiguration."""
self.assertTrue(self.udp_config.enable)
self.assertEqual(self.udp_config.port, 14001)
self.assertEqual(self.udp_config.filter_log_udp, ecal.eCAL_Logging_Filter.log_filter_default)

def test_enable_property(self):
"""Test setting the enable property."""
self.udp_config.enable = False
self.assertFalse(self.udp_config.enable)

self.udp_config.enable = True
self.assertTrue(self.udp_config.enable)

def test_port_property(self):
"""Test setting the port property."""
self.udp_config.port = 15000
self.assertEqual(self.udp_config.port, 15000)

def test_filter_log_udp_property(self):
"""Test setting the filter_log_udp property."""
self.udp_config.filter_log_udp = ecal.eCAL_Logging_Filter.log_level_warning
self.assertEqual(self.udp_config.filter_log_udp, ecal.eCAL_Logging_Filter.log_level_warning)


class TestSinksConfiguration(unittest.TestCase):

def setUp(self):
"""Create an instance of SinksConfiguration before each test."""
self.sinks_config = ecal.SinksConfiguration()

def test_default_values(self):
"""Test the default values of the SinksConfiguration."""
self.assertTrue(self.sinks_config.console.enable)
self.assertFalse(self.sinks_config.file.enable)
self.assertTrue(self.sinks_config.udp.enable)
self.assertEqual(self.sinks_config.udp.port, 14001)

def test_console_configuration(self):
"""Test the console configuration inside sinks."""
self.sinks_config.console.enable = False
self.assertFalse(self.sinks_config.console.enable)

def test_file_configuration(self):
"""Test the file configuration inside sinks."""
self.sinks_config.file.enable = True
self.sinks_config.file.path = "/tmp/test_log.log"
self.assertTrue(self.sinks_config.file.enable)
self.assertEqual(self.sinks_config.file.path, "/tmp/test_log.log")

def test_udp_configuration(self):
"""Test the UDP configuration inside sinks."""
self.sinks_config.udp.port = 16000
self.assertEqual(self.sinks_config.udp.port, 16000)


class TestLoggingConfiguration(unittest.TestCase):

def setUp(self):
"""Create an instance of LoggingConfiguration before each test."""
self.logging_config = ecal.LoggingConfiguration()

def test_default_values(self):
"""Test the default values of the LoggingConfiguration."""
self.assertIsInstance(self.logging_config.sinks, ecal.SinksConfiguration)

def test_modify_sinks(self):
"""Test modifying sinks in LoggingConfiguration."""
self.logging_config.sinks.console.enable = False
self.assertFalse(self.logging_config.sinks.console.enable)
self.logging_config.sinks.file.path = "/var/log/my_app.log"
self.assertEqual(self.logging_config.sinks.file.path, "/var/log/my_app.log")


if __name__ == "__main__":
unittest.main()

0 comments on commit bec8772

Please sign in to comment.