1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2024 Huawei Device Co., Ltd. 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18# flake8: noqa 19# pylint: skip-file 20 21import os 22import pytest # type: ignore 23from unittest import TestCase 24from vmb.shell import ShellUnix 25 26here = os.path.realpath(os.path.dirname(__file__)) 27sh = ShellUnix() 28 29 30def posix_only(f): 31 def s(*args): 32 if 'posix' != os.name: 33 pytest.skip("POSIX-only test") 34 else: 35 f(*args) 36 return s 37 38 39@posix_only 40def test_unix_ls() -> None: 41 this_file = os.path.basename(__file__) 42 res = sh.run(f'ls -1 {here}') 43 TestCase().assertTrue(res.grep(this_file) == this_file) 44 45 46@posix_only 47def test_unix_cwd() -> None: 48 this_file = os.path.basename(__file__) 49 this_dir = os.path.dirname(__file__) 50 res = sh.run(f'ls -1 .', cwd=this_dir) 51 TestCase().assertTrue(res.grep(this_file) == this_file) 52 53 54@posix_only 55def test_unix_measure_time() -> None: 56 res = sh.run('sleep 1', measure_time=True, timeout=3) 57 test = TestCase() 58 test.assertTrue(res.tm > 0.9) 59 test.assertTrue(res.rss > 0) 60