|
| 1 | +# Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +""" |
| 16 | +Test system_utils methods. |
| 17 | +""" |
| 18 | + |
| 19 | +import os |
| 20 | +from py_utils.system.system_utils import is_linux, is_windows |
| 21 | + |
| 22 | + |
| 23 | +def test_is_linux(): |
| 24 | + # Test case 1: Running the script on a Linux system |
| 25 | + os.name = 'posix' |
| 26 | + assert (is_linux() is True) |
| 27 | + |
| 28 | + # Test case 2: Running the script on a Windows system |
| 29 | + os.name = 'nt' |
| 30 | + assert (is_linux() is False) |
| 31 | + |
| 32 | + # Test case 3: Running the script on a different operating system |
| 33 | + os.name = 'mac' |
| 34 | + assert (is_linux() is False) |
| 35 | + |
| 36 | + |
| 37 | +def test_is_windows(): |
| 38 | + # Test case 1: Running the script on a Linux system |
| 39 | + os.name = 'posix' |
| 40 | + assert (is_windows() is False) |
| 41 | + |
| 42 | + # Test case 2: Running the script on a Windows system |
| 43 | + os.name = 'nt' |
| 44 | + assert (is_windows() is True) |
| 45 | + |
| 46 | + # Test case 3: Running the script on a different operating system |
| 47 | + os.name = 'mac' |
| 48 | + assert (is_windows() is False) |
| 49 | + |
| 50 | + |
| 51 | +# Run the tests |
| 52 | +test_is_linux() |
| 53 | +test_is_windows() |
0 commit comments