diff --git a/py_utils/py_utils/system/__init__.py b/py_utils/py_utils/system/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/py_utils/py_utils/system/system_utils.py b/py_utils/py_utils/system/system_utils.py new file mode 100644 index 00000000..f92c946e --- /dev/null +++ b/py_utils/py_utils/system/system_utils.py @@ -0,0 +1,37 @@ +# Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +This file contains system utils. +""" + +import os + + +def is_linux() -> bool: + """ + @brief Check if the script is running in a Linux environment. + + @return: True if the script is running in a Linux environment, False otherwise. + """ + return os.name == 'posix' + + +def is_windows() -> bool: + """ + @brief Check if the script is running in a Windows environment. + + @return: True if the script is running in a Windows environment, False otherwise. + """ + return os.name == 'nt' diff --git a/py_utils/setup.py b/py_utils/setup.py index 73807c1d..e4514c17 100644 --- a/py_utils/setup.py +++ b/py_utils/setup.py @@ -10,6 +10,7 @@ package_name, package_name + '/debugging', package_name + '/logging', + package_name + '/system', package_name + '/time', package_name + '/wait', ] diff --git a/py_utils/test/py_utils/import/test_import.py b/py_utils/test/py_utils/import/test_import.py index 3408537d..ed689976 100644 --- a/py_utils/test/py_utils/import/test_import.py +++ b/py_utils/test/py_utils/import/test_import.py @@ -18,6 +18,7 @@ import py_utils.debugging.debug_utils # noqa: F401 import py_utils.logging.log_utils # noqa: F401 +import py_utils.system.system_utils # noqa: F401 import py_utils.time.Timer # noqa: F401 import py_utils.wait.WaitHandler # noqa: F401 import py_utils.wait.BooleanWaitHandler # noqa: F401 diff --git a/py_utils/test/py_utils/unittest/system/test_System.py b/py_utils/test/py_utils/unittest/system/test_System.py new file mode 100644 index 00000000..016dc9e5 --- /dev/null +++ b/py_utils/test/py_utils/unittest/system/test_System.py @@ -0,0 +1,71 @@ +# Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Test system_utils methods. +""" + +import os + +from py_utils.system.system_utils import is_linux, is_windows + + +def test_is_test(): + assert True + + +def test_is_linux(): + + # Test case 0: Running the script in its own system + # NOTE: this could use same method as the function internally, but it is what it is. + if os.name == 'posix': + assert is_linux() + + if os.name == 'nt': + assert not is_linux() + +# # Test case 1: Running the script on a Linux system +# os.name = 'posix' +# assert is_linux() + +# # Test case 2: Running the script on a Windows system +# os.name = 'nt' +# assert not is_linux() + +# # Test case 3: Running the script on a different operating system +# os.name = 'mac' +# assert not is_linux() + + +def test_is_windows(): + + # Test case 0: Running the script in its own system + # NOTE: this could use same method as the function internally, but it is what it is. + if os.name == 'posix': + assert not is_windows() + + if os.name == 'nt': + assert is_windows() + +# # Test case 1: Running the script on a Linux system +# os.name = 'posix' +# assert not is_windows() + +# # Test case 2: Running the script on a Windows system +# os.name = 'nt' +# assert is_windows() + +# # Test case 3: Running the script on a different operating system +# os.name = 'mac' +# assert not is_windows()