Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
37 changes: 37 additions & 0 deletions py_utils/py_utils/system/system_utils.py
Original file line number Diff line number Diff line change
@@ -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'
1 change: 1 addition & 0 deletions py_utils/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package_name,
package_name + '/debugging',
package_name + '/logging',
package_name + '/system',
package_name + '/time',
package_name + '/wait',
]
Expand Down
1 change: 1 addition & 0 deletions py_utils/test/py_utils/import/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 71 additions & 0 deletions py_utils/test/py_utils/unittest/system/test_System.py
Original file line number Diff line number Diff line change
@@ -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()