1
0
mirror of https://github.com/TheLocehiliosan/yadm synced 2024-10-27 20:34:27 +00:00
TheLocehiliosan_yadm/test/test_unit_set_os.py
Tim Byrne e7f9616b39
Rewrite testing system (#119)
The new test system is written with py.test. These tests are more
comprehensive, run faster by an order of magnitude, and are far more
maintainable. The tests themselves conform to PEP8.
2019-02-20 07:48:25 -06:00

37 lines
1.1 KiB
Python

"""Unit tests: set_operating_system"""
import pytest
@pytest.mark.parametrize(
'proc_value, expected_os', [
('missing', 'uname'),
('has Microsoft inside', 'WSL'),
('another value', 'uname'),
], ids=[
'/proc/version missing',
'/proc/version includes MS',
'/proc/version excludes MS',
])
def test_set_operating_system(
runner, paths, tst_sys, proc_value, expected_os):
"""Run set_operating_system and test result"""
# Normally /proc/version (set in PROC_VERSION) is inspected to identify
# WSL. During testing, we will override that value.
proc_version = paths.root.join('proc_version')
if proc_value != 'missing':
proc_version.write(proc_value)
script = f"""
YADM_TEST=1 source {paths.pgm}
PROC_VERSION={proc_version}
set_operating_system
echo $OPERATING_SYSTEM
"""
run = runner(command=['bash'], inp=script)
assert run.success
assert run.err == ''
if expected_os == 'uname':
expected_os = tst_sys
assert run.out.rstrip() == expected_os