From fe3cc00a85ef1864f527dbcc84ab83144fa8c050 Mon Sep 17 00:00:00 2001 From: Irene Bandera Date: Fri, 9 Jun 2023 09:39:57 +0200 Subject: [PATCH 1/5] Add system_utils Signed-off-by: Irene Bandera --- py_utils/py_utils/system/__init__.py | 0 py_utils/py_utils/system/system_utils.py | 35 ++++++++++++++++++++++++ py_utils/setup.py | 1 + 3 files changed, 36 insertions(+) create mode 100644 py_utils/py_utils/system/__init__.py create mode 100644 py_utils/py_utils/system/system_utils.py 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..027f2eb4 --- /dev/null +++ b/py_utils/py_utils/system/system_utils.py @@ -0,0 +1,35 @@ +# 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', ] From 08cd68b0fe804e20fba05632c206243297997681 Mon Sep 17 00:00:00 2001 From: Irene Bandera Date: Fri, 9 Jun 2023 10:16:00 +0200 Subject: [PATCH 2/5] Fix python linter Signed-off-by: Irene Bandera --- py_utils/py_utils/system/system_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/py_utils/py_utils/system/system_utils.py b/py_utils/py_utils/system/system_utils.py index 027f2eb4..f92c946e 100644 --- a/py_utils/py_utils/system/system_utils.py +++ b/py_utils/py_utils/system/system_utils.py @@ -18,6 +18,7 @@ import os + def is_linux() -> bool: """ @brief Check if the script is running in a Linux environment. @@ -26,6 +27,7 @@ def is_linux() -> bool: """ return os.name == 'posix' + def is_windows() -> bool: """ @brief Check if the script is running in a Windows environment. From 4b66e8ee698be2195bca7b26b2ffb1873fe60fdb Mon Sep 17 00:00:00 2001 From: Irene Bandera Date: Fri, 9 Jun 2023 10:56:10 +0200 Subject: [PATCH 3/5] Add tests Signed-off-by: Irene Bandera --- py_utils/test/py_utils/import/test_import.py | 1 + .../py_utils/unittest/system/test_System.py | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 py_utils/test/py_utils/unittest/system/test_System.py 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..0a693969 --- /dev/null +++ b/py_utils/test/py_utils/unittest/system/test_System.py @@ -0,0 +1,53 @@ +# 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_linux(): + # Test case 1: Running the script on a Linux system + os.name = 'posix' + assert (is_linux() is True) + + # Test case 2: Running the script on a Windows system + os.name = 'nt' + assert (is_linux() is False) + + # Test case 3: Running the script on a different operating system + os.name = 'mac' + assert (is_linux() is False) + + +def test_is_windows(): + # Test case 1: Running the script on a Linux system + os.name = 'posix' + assert (is_windows() is False) + + # Test case 2: Running the script on a Windows system + os.name = 'nt' + assert (is_windows() is True) + + # Test case 3: Running the script on a different operating system + os.name = 'mac' + assert (is_windows() is False) + + +# Run the tests +test_is_linux() +test_is_windows() From d2dfde8a14801cf9b4dbfd70f6a08d7c08729888 Mon Sep 17 00:00:00 2001 From: Irene Bandera Date: Mon, 12 Jun 2023 10:05:25 +0200 Subject: [PATCH 4/5] Apply changes Signed-off-by: Irene Bandera --- .../py_utils/unittest/system/test_System.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/py_utils/test/py_utils/unittest/system/test_System.py b/py_utils/test/py_utils/unittest/system/test_System.py index 0a693969..ec51327e 100644 --- a/py_utils/test/py_utils/unittest/system/test_System.py +++ b/py_utils/test/py_utils/unittest/system/test_System.py @@ -17,37 +17,33 @@ """ import os + from py_utils.system.system_utils import is_linux, is_windows def test_is_linux(): # Test case 1: Running the script on a Linux system os.name = 'posix' - assert (is_linux() is True) + assert is_linux() # Test case 2: Running the script on a Windows system os.name = 'nt' - assert (is_linux() is False) + assert not is_linux() # Test case 3: Running the script on a different operating system os.name = 'mac' - assert (is_linux() is False) + assert not is_linux() def test_is_windows(): # Test case 1: Running the script on a Linux system os.name = 'posix' - assert (is_windows() is False) + assert not is_windows() # Test case 2: Running the script on a Windows system os.name = 'nt' - assert (is_windows() is True) + assert is_windows() # Test case 3: Running the script on a different operating system os.name = 'mac' - assert (is_windows() is False) - - -# Run the tests -test_is_linux() -test_is_windows() + assert not is_windows() From ecdd3ee5dadf417b3f0ce99dde258721dba732e1 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 20 Jun 2023 14:35:42 +0200 Subject: [PATCH 5/5] TMP test windows system test Signed-off-by: jparisu --- .../py_utils/unittest/system/test_System.py | 58 +++++++++++++------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/py_utils/test/py_utils/unittest/system/test_System.py b/py_utils/test/py_utils/unittest/system/test_System.py index ec51327e..016dc9e5 100644 --- a/py_utils/test/py_utils/unittest/system/test_System.py +++ b/py_utils/test/py_utils/unittest/system/test_System.py @@ -21,29 +21,51 @@ from py_utils.system.system_utils import is_linux, is_windows +def test_is_test(): + assert True + + def test_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 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 3: Running the script on a different operating system - os.name = 'mac' - assert not 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 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 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() +# # Test case 3: Running the script on a different operating system +# os.name = 'mac' +# assert not is_windows()