From a8003d972a93e3a242d723685d61bdd11d03f91c Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Fri, 16 Apr 2021 17:09:56 +0100 Subject: [PATCH 1/3] setup: Add pytest as 'test' dependency --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 96262e116..e94d9c970 100644 --- a/setup.py +++ b/setup.py @@ -99,6 +99,7 @@ 'doc': ['sphinx'], 'monsoon': ['python-gflags'], 'acme': ['pandas', 'numpy'], + 'test': ['pytest'], }, # https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ From 887bf2809677479cabaaee7a3e337aa1678d15b9 Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Fri, 16 Apr 2021 17:10:32 +0100 Subject: [PATCH 2/3] tests/localtarget: Add initial tests for local target Add initial pytest tests for exercising basic functionality of a LocalLinuxTarget --- tests/test_local_linux_target.py | 140 +++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 tests/test_local_linux_target.py diff --git a/tests/test_local_linux_target.py b/tests/test_local_linux_target.py new file mode 100644 index 000000000..5e4febf64 --- /dev/null +++ b/tests/test_local_linux_target.py @@ -0,0 +1,140 @@ +import os +import tempfile +import pytest + +from devlib import LocalLinuxTarget + + +@pytest.fixture(scope="class") +def target(): + target = LocalLinuxTarget(connection_settings={'unrooted': True}) + yield target + target.disconnect() + + +class TestLocalLinuxMethods: + ''' + Verify basic functionality of LocalTarget and LocalConnection + ''' + + def test_connection(self, target): + target.check_connection() + + def test_echo(self, target): + expected = 'A TEST STRING' + assert target.execute('echo {}'.format(expected)).strip() == expected + + def test_busybox_echo(self, target): + assert target.file_exists(target.busybox) + expected = 'A TEST STRING' + assert target.execute('{} echo {}'.format(target.busybox, expected)).strip() == expected + + def test_background_command(self, target): + expected = 'A TEST STRING' + bg_cmd = target.background('echo {}'.format(expected)) + assert bg_cmd + bg_cmd.wait() + assert bg_cmd.stdout.read().strip().decode('utf-8') == expected + + def test_get_work_directory(self, target): + assert target.get_workpath('test') + + def test_push(self, target): + with tempfile.NamedTemporaryFile() as src_file: + dst = target.get_workpath('test') + target.push(src_file.name, dst) + assert target.file_exists(dst) + target.remove(dst) + + def test_pull(self, target): + src = target.get_workpath('test') + target.execute('touch {}'.format(src)) + dst = tempfile.NamedTemporaryFile().name + target.pull(src, dst) + assert os.path.exists(dst) + os.remove(dst) + target.remove(dst) + + def test_installation(self, target): + bin_name = 'test_binary' + with tempfile.NamedTemporaryFile() as src_file: + path = target.install(src_file.name, with_name=bin_name) + assert path + assert target.is_installed(bin_name) + target.uninstall(bin_name) + + def test_shutils_setup(self, target): + assert target.shutils + + def test_directories_exists(self, target): + assert target.directory_exists(target.working_directory) + assert target.directory_exists(target.executables_directory) + + +class TestLocalTargetAttributes: + + ''' + Exercise target attributes, we don't know the machine the + tests will be running on, only root status, so just check the + call executes correctly. + ''' + + def test_core_name(self, target): + assert target.core_names + + def test_clusters(self, target): + assert target.core_names + + def test_is_connected(self, target): + assert target.is_connected + + def test_not_connected_as_root(self, target): + assert not target.connected_as_root + + def test_is_unrooted(self, target): + assert not target.is_rooted + + def test_needs_su(self, target): + assert not target.needs_su + + def test_kernel_version(self, target): + assert target.kernel_version + + def test_hostid(self, target): + assert target.hostid is not None + + def test_hostname(self, target): + assert target.hostname is not None + + def test_os_version(self, target): + assert target.os_version is not None + + def test_model(self, target): + target.model # Likely to be None + + def test_abi(self, target): + assert target.abi is not None + + def test_cpuinfo(self, target): + assert target.cpuinfo is not None + + def test_number_of_cpus(self, target): + assert target.number_of_cpus is not None + + def test_number_of_nodes(self, target): + assert target.number_of_nodes is not None + + def test_list_nodes_cpus(self, target): + assert target.list_nodes_cpus is not None + + def test_config(self, target): + assert target.config is not None + + def test_user(self, target): + assert target.user is not None + + def test_page_size_kb(self, target): + assert target.user is not None + + def test_page_size_kb(self, target): + assert target.user is not None From 9f4ea9889363e593459db63e08f24dd074dc376b Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Fri, 16 Apr 2021 17:21:28 +0100 Subject: [PATCH 3/3] github_actions: Enable initial pytests --- .github/workflows/main.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..d37625b5b --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,35 @@ +name: Devlib Test Suite + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + types: [opened, synchronize, reopened, ready_for_review] + schedule: + - cron: 0 2 * * * + # Allows runing this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + Run-PyTest-Tests: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.5, 3.6, 3.7, 3.8, 3.9] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: git-bash + uses: pkg-src/github-action-git-bash@v1.1 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + cd $GITHUB_WORKSPACE && pip install .[test] + pip install pytest + - name: Run pytest tests + run: | + pytest