as we have different suite/case definition as unittest, it's confusing
to use assertions in unittest. So use the separated asserts package.
This commit is contained in:
Chi Song 2020-10-20 13:23:52 +08:00
Родитель de2d720e0e
Коммит 447011b1e7
6 изменённых файлов: 28 добавлений и 13 удалений

Просмотреть файл

@ -1,3 +1,5 @@
import asserts
from lisa import TestCaseMetadata, TestSuite, TestSuiteMetadata
from lisa.operating_system import Linux
from lisa.tools import Echo, Uname
@ -39,9 +41,9 @@ class HelloWorld(TestSuite):
echo = node.tools[Echo]
hello_world = "hello world!"
result = echo.run(hello_world)
self.assertEqual(hello_world, result.stdout)
self.assertEqual("", result.stderr)
self.assertEqual(0, result.exit_code)
asserts.assert_equal(hello_world, result.stdout)
asserts.assert_equal("", result.stderr)
asserts.assert_equal(0, result.exit_code)
@TestCaseMetadata(
description="""
@ -53,7 +55,7 @@ class HelloWorld(TestSuite):
node = self.environment.default_node
# use it once like this way before use short cut
node.tools[Echo]
self.assertEqual("bye!", str(node.tools.echo("bye!")))
asserts.assert_equal("bye!", str(node.tools.echo("bye!")))
def before_suite(self) -> None:
self.log.info("setup my test suite")

Просмотреть файл

@ -1,3 +1,5 @@
import asserts
from lisa import TestCaseMetadata, TestSuite, TestSuiteMetadata
from lisa.testsuite import simple_requirement
from lisa.tools import Lscpu, Ntttcp
@ -47,12 +49,12 @@ class MutipleNodesDemo(TestSuite):
f"-s {server_node.internal_address} -P 1 -n 1 -t 5 -W 1", no_info_log=False
)
server_result = server_process.wait_result(timeout=10)
self.assertEqual(
asserts.assert_equal(
0,
client_result.exit_code,
f"client exit code [{client_result.exit_code}] should be 0.",
)
self.assertEqual(
asserts.assert_equal(
0,
server_result.exit_code,
f"server exit code [{server_result.exit_code}] should be 0.",

Просмотреть файл

@ -1,5 +1,7 @@
from pathlib import Path
import asserts
from lisa import TestCaseMetadata, TestSuite, TestSuiteMetadata
from lisa.executable import CustomScript, CustomScriptBuilder
from lisa.operating_system import Windows
@ -39,10 +41,10 @@ class WithScript(TestSuite):
self.log.info(f"first run finished within {timer1}")
timer2 = create_timer()
result2 = script.run()
self.assertEqual(result1.stdout, result2.stdout)
asserts.assert_equal(result1.stdout, result2.stdout)
if node.is_remote:
# the timer will be significant different on a remote node.
self.assertGreater(
asserts.assert_greater(
timer1.elapsed(),
timer2.elapsed(),
"the second time should be faster, without uploading",

Просмотреть файл

@ -1,6 +1,5 @@
from __future__ import annotations
import unittest
from abc import ABCMeta
from dataclasses import dataclass
from enum import Enum
@ -257,7 +256,7 @@ class TestCaseRuntimeData:
return cloned
class TestSuite(unittest.TestCase, Action, metaclass=ABCMeta):
class TestSuite(Action, metaclass=ABCMeta):
def __init__(
self,
environment: Environment,

15
poetry.lock сгенерированный
Просмотреть файл

@ -6,6 +6,14 @@ category = "dev"
optional = false
python-versions = "*"
[[package]]
name = "asserts"
version = "0.11.0"
description = "Stand-alone Assertions"
category = "main"
optional = false
python-versions = ">=3.6"
[[package]]
name = "asttokens"
version = "2.0.4"
@ -906,13 +914,16 @@ socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7,<2.0)"]
[metadata]
lock-version = "1.1"
python-versions = "^3.8"
content-hash = "64460929c241bcef1148ffbd3b8994e5b4b501373aca3dad90c052deecf70321"
content-hash = "e6a7b2166380656793d4410d58840a229ce8ddb3864d94f0237c99323ac4a488"
[metadata.files]
appdirs = [
{file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"},
{file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"},
]
asserts = [
{file = "asserts-0.11.0-py2.py3-none-any.whl", hash = "sha256:8e11c7645ee41bf66547bfd1d916ac482acdfb09688247d8e7718e8bc1a31ea7"},
]
asttokens = [
{file = "asttokens-2.0.4-py2.py3-none-any.whl", hash = "sha256:766d3352908730efb20b95ae22db0f1cb1bedb67c6071fcffb5c236ea673f2f7"},
{file = "asttokens-2.0.4.tar.gz", hash = "sha256:a42e57e28f2ac1c85ed9b1f84109401427e5c63c04f61d15b8842b027eec5128"},
@ -1232,8 +1243,6 @@ pynacl = [
{file = "PyNaCl-1.4.0-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:7757ae33dae81c300487591c68790dfb5145c7d03324000433d9a2c141f82af7"},
{file = "PyNaCl-1.4.0-cp35-abi3-macosx_10_10_x86_64.whl", hash = "sha256:757250ddb3bff1eecd7e41e65f7f833a8405fede0194319f87899690624f2122"},
{file = "PyNaCl-1.4.0-cp35-abi3-manylinux1_x86_64.whl", hash = "sha256:30f9b96db44e09b3304f9ea95079b1b7316b2b4f3744fe3aaecccd95d547063d"},
{file = "PyNaCl-1.4.0-cp35-abi3-win32.whl", hash = "sha256:4e10569f8cbed81cb7526ae137049759d2a8d57726d52c1a000a3ce366779634"},
{file = "PyNaCl-1.4.0-cp35-abi3-win_amd64.whl", hash = "sha256:c914f78da4953b33d4685e3cdc7ce63401247a21425c16a39760e282075ac4a6"},
{file = "PyNaCl-1.4.0-cp35-cp35m-win32.whl", hash = "sha256:06cbb4d9b2c4bd3c8dc0d267416aaed79906e7b33f114ddbf0911969794b1cc4"},
{file = "PyNaCl-1.4.0-cp35-cp35m-win_amd64.whl", hash = "sha256:511d269ee845037b95c9781aa702f90ccc36036f95d0f31373a6a79bd8242e25"},
{file = "PyNaCl-1.4.0-cp36-cp36m-win32.whl", hash = "sha256:11335f09060af52c97137d4ac54285bcb7df0cef29014a1a4efe64ac065434c4"},

Просмотреть файл

@ -19,6 +19,7 @@ azure-identity = {version = "^1.4.0", allow-prereleases = true}
azure-mgmt-resource = {version = "^15.0.0-beta.1", allow-prereleases = true}
azure-mgmt-compute = {version = "^17.0.0-beta.1", allow-prereleases = true}
azure-mgmt-network = {version = "^16.0.0-beta.1", allow-prereleases = true}
asserts = "^0.11.0"
[tool.poetry.dev-dependencies]
black = "^20.8b1"