Skip to content

Commit

Permalink
Changes for CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Sep 26, 2023
1 parent 2c44186 commit 5ce91e3
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 4 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/build_wheel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Build from source using tox.
name: build_tox
on: [push, pull_request]
permissions: read-all
jobs:
build_tox:
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- python-version: '3.7'
toxenv: 'py37'
- python-version: '3.8'
toxenv: 'py38'
- python-version: '3.9'
toxenv: 'py39'
- python-version: '3.10'
toxenv: 'py310'
- python-version: '3.11'
toxenv: 'py311'
- python-version: '3.12'
toxenv: 'py312'
steps:
- uses: actions/checkout@v3
- name: Install build dependencies
run: |
sudo add-apt-repository universe &&
sudo add-apt-repository -y ppa:deadsnakes/ppa &&
sudo add-apt-repository -y ppa:gift/dev &&
sudo apt-get update &&
sudo apt-get install -y autoconf automake autopoint build-essential git libtool pkg-config python${{ matrix.python-version }} python${{ matrix.python-version }}-dev python${{ matrix.python-version }}-venv python3-distutils python3-pip python3-setuptools
- name: Install tox
run: |
python3 -m pip install tox
- name: Download test data
run: |
if test -x "synctestdata.sh"; then ./synctestdata.sh; fi
- name: Prepare build
run: |
./synclibs.sh --use-head && ./autogen.sh
- name: Build Python wheel
run: |
tox -e${{ matrix.toxenv }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Files to ignore by git
#
# Version: 20230923
# Version: 20230926

# Generic auto-generated build files
*~
Expand All @@ -25,11 +25,13 @@
*.swp
*.Tpo
*.trs
*.whl
/*.egg-info/
.deps
.dirstamp
.libs
.tox
__pycache__
INSTALL
Makefile
Makefile.bcc
Expand Down
1 change: 1 addition & 0 deletions setup.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = liblnk-python
version = @VERSION@
description = Python bindings module for liblnk
long_description = Python bindings module for liblnk
author = Joachim Metz
author_email = [email protected]
license = GNU Lesser General Public License v3 or later (LGPLv3+)
Expand Down
49 changes: 48 additions & 1 deletion tests/pylnk_test_data_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,61 @@
class DatablockTypeTests(unittest.TestCase):
"""Tests the data_block type."""

def test_get_signature(self):
"""Tests the get_signature function and signature property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")

lnk_file = pylnk.file()

lnk_file.open(test_source)

number_of_data_blocks = lnk_file.get_number_of_data_blocks()
if number_of_data_blocks:
data_block = lnk_file.get_data_block(0)
self.assertIsNotNone(data_block)

signature = data_block.get_signature()
self.assertIsNotNone(signature)

self.assertIsNotNone(data_block.signature)

lnk_file.close()

def test_get_data(self):
"""Tests the get_data function and data property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")

lnk_file = pylnk.file()

lnk_file.open(test_source)

number_of_data_blocks = lnk_file.get_number_of_data_blocks()
if number_of_data_blocks:
data_block = lnk_file.get_data_block(0)
self.assertIsNotNone(data_block)

data = data_block.get_data()
self.assertIsNotNone(data)

self.assertIsNotNone(data_block.data)

lnk_file.close()


if __name__ == "__main__":
argument_parser = argparse.ArgumentParser()

argument_parser.add_argument(
"source", nargs="?", action="store", metavar="PATH",
default=None, help="path of the source file.")

options, unknown_options = argument_parser.parse_known_args()
unknown_options.insert(0, sys.argv[0])


setattr(unittest, "source", options.source)

unittest.main(argv=unknown_options, verbosity=2)
17 changes: 17 additions & 0 deletions tests/pylnk_test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,23 @@ def test_get_number_of_data_blocks(self):

lnk_file.close()

def test_get_data_block(self):
"""Tests the get_data_block function."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")

lnk_file = pylnk.file()

lnk_file.open(test_source)

number_of_data_blocks = lnk_file.get_number_of_data_blocks()
if number_of_data_blocks:
data_block = lnk_file.get_data_block(0)
self.assertIsNotNone(data_block)

lnk_file.close()


if __name__ == "__main__":
argument_parser = argparse.ArgumentParser()
Expand Down
62 changes: 62 additions & 0 deletions tests/runtests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python
#
# Script to run Python test scripts.
#
# Copyright (C) 2009-2023, Joachim Metz <[email protected]>
#
# Refer to AUTHORS for acknowledgements.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import glob
import os
import sys
import unittest


if __name__ == "__main__":
print(f"Using Python version {sys.version!s}")

test_loader = unittest.TestLoader()
test_runner = unittest.TextTestRunner(verbosity=2)

test_scripts = test_loader.discover("tests", pattern="*.py")

test_profile = ".pylnk"
input_glob = "*.lnk"

ignore_list = set()

ignore_file_path = f"tests/input/{test_profile}/ignore"
if os.path.isfile(ignore_file_path):
with open(ignore_file_path, "r", encoding="utf-8") as file_object:
ignore_list = set([line.strip() for line in file_object.readlines()])

source_file = None

for test_set in glob.glob("tests/input/*"):
test_set = test_set.rsplit('/', maxsplit=1)[-1]
if not test_set or test_set[0] == '.' or test_set in ignore_list:
continue

source_files = glob.glob(f"tests/input/{test_set:s}/{input_glob:s}")
if source_files:
source_file = source_files[0]
break

setattr(unittest, "source", source_file)

test_results = test_runner.run(test_scripts)
if not test_results.wasSuccessful():
sys.exit(1)
2 changes: 1 addition & 1 deletion tests/test_python_module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ EXIT_FAILURE=1;
EXIT_IGNORE=77;

TEST_FUNCTIONS="";
TEST_FUNCTIONS_WITH_INPUT="file support";
TEST_FUNCTIONS_WITH_INPUT="data_block file support";
OPTION_SETS="";

TEST_TOOL_DIRECTORY=".";
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ deps =
setuptools
wheel
commands =
python -m build --no-isolation --wheel
python -m pip wheel --no-build-isolation --wheel-dir=dist liblnk-python
python -m pip install --no-index --find-links=dist liblnk-python
python tests/runtests.py

0 comments on commit 5ce91e3

Please sign in to comment.