Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempts to publish coverage invo #807

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,47 @@ jobs:
with:
files: coverage.json

mac-unittest:
name: python${{ matrix.python-version }}
runs-on: macos-latest

strategy:
matrix:
python-version:
- '3.11'

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install test dependencies
run: |
brew install modules alisw/system-deps/o2-full-deps
python3 -m pip install --upgrade tox tox-gh-actions coverage

- name: Run tests
run: tox -e darwin

- name: Convert coverage information
if: ${{ always() && github.event.repository.owner.login == 'alisw' }}
run: |
coverage combine .tox/coverage.*
# Codecov only understands XML, JSON and LCOV files.
# Apparently, patching os.readlink in unit tests interferes with
# finding some source files, but our source shouldn't be affected, so
# ignore these errors.
coverage json --ignore-errors -o coverage.json

- name: Upload coverage information
if: ${{ always() && github.event.repository.owner.login == 'alisw' }}
uses: codecov/codecov-action@v3
with:
files: coverage.json

lint:
name: lint
runs-on: ubuntu-latest
Expand Down
27 changes: 18 additions & 9 deletions alibuild_helpers/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import sys
import os
import re
import platform

from datetime import datetime
try:
from collections import OrderedDict
Expand Down Expand Up @@ -131,13 +133,21 @@
return decode_with_fallback(s) % kwds


def doDetectArch(hasOsRelease, osReleaseLines, platformTuple, platformSystem, platformProcessor):
if platformSystem == "Darwin":
import platform
if platform.machine() == "x86_64":
return "osx_x86-64"
else:
return "osx_arm64"
def doDetectArch(hasOsRelease, osReleaseLines, platformTuple, pSystem, platformProcessor):
print(platformTuple)
print(pSystem)
print(pSystem == "Darwin")

if pSystem == "Darwin":
print("Show must go on")

Check warning on line 142 in alibuild_helpers/utilities.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/utilities.py#L142

Added line #L142 was not covered by tests
if pSystem == "Darwin":
processor = platformProcessor
if not processor:
if platform.machine() == "x86_64":
processor = "x86-64"

Check warning on line 147 in alibuild_helpers/utilities.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/utilities.py#L144-L147

Added lines #L144 - L147 were not covered by tests
else:
processor = "arm64"
return "osx_%s" % processor.replace("_", "-")

Check warning on line 150 in alibuild_helpers/utilities.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/utilities.py#L149-L150

Added lines #L149 - L150 were not covered by tests
distribution, version, flavour = platformTuple
distribution = distribution.lower()
# If platform.dist does not return something sensible,
Expand Down Expand Up @@ -191,7 +201,6 @@
osReleaseLines = []
hasOsRelease = False
try:
import platform
if platform.system() == "Darwin":
if platform.machine() == "x86_64":
return "osx_x86-64"
Expand All @@ -200,7 +209,7 @@
except:
pass
try:
import platform, distro
import distro
platformTuple = distro.linux_distribution()
platformSystem = platform.system()
platformProcessor = platform.processor()
Expand Down
13 changes: 13 additions & 0 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@

architecturePayloads = [
['osx_x86-64', False, [], ('','',''), 'Darwin', 'x86-64'],
['osx_arm64', False, [], ('','',''), 'Darwin', 'arm64'],
['slc5_x86-64', False, [], ('redhat', '5.XX', 'Boron'), 'Linux', 'x86-64'],
['slc6_x86-64', False, [], ('centos', '6.X', 'Carbon'), 'Linux', 'x86-64'],
['slc7_x86-64', False, [], ('centos', '7.X', 'Ptor'), 'Linux', 'x86-64'],
Expand All @@ -131,11 +132,23 @@
['sabayon2_x86-64', True, SABAYON2_OS_RELEASE.split("\n"), ('gentoo', '2.2', ''), 'Linux', 'x86_64']
]

macOSArchitecturePayloads = [
['osx_x86-64', False, [], ('','',''), 'Darwin', 'x86_64'],
['osx_arm64', False, [], ('','',''), 'Darwin', 'arm64'],
]

class TestUtilities(unittest.TestCase):
def test_osx(self):
for payload in architecturePayloads:
result, hasOsRelease, osReleaseLines, platformTuple, platformSystem, platformProcessor = payload
self.assertEqual(result, doDetectArch(hasOsRelease, osReleaseLines, platformTuple, platformSystem, platformProcessor))
# Test by mocking platform.processor
def test_osx_mock(self):
for payload in macOSArchitecturePayloads:
result, hasOsRelease, osReleaseLines, platformTuple, platformSystem, platformProcessor = payload
with patch('platform.machine', return_value=platformProcessor):
platformProcessor = None
self.assertEqual(result, doDetectArch(hasOsRelease, osReleaseLines, platformTuple, platformSystem, None))
def test_Hasher(self):
h = Hasher()
h("foo")
Expand Down
27 changes: 14 additions & 13 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
minversion = 3.20
envlist = lint, py{27, 36, 37, 38, 39, 310, 311}
envlist = lint, py{27, 36, 37, 38, 39, 310, 311}, darwin

[gh-actions]
# The "lint" job is run separately.
Expand Down Expand Up @@ -57,6 +57,8 @@ setenv =
# Keep coverage info for later upload, if needed. Files in {envtmpdir} are
# deleted after each run.
COVERAGE_FILE = {toxworkdir}/coverage.{envname}
ARCHITECTURE = slc7_x86-64
darwin: ARCHITECTURE = osx_x86-64

changedir = {envtmpdir}
commands =
Expand All @@ -74,14 +76,12 @@ commands =

coverage run --source={toxinidir} -a {toxinidir}/aliBuild version

coverage run --source={toxinidir} -a -m unittest discover {toxinidir}/tests

git clone -b O2-v1.3.0 --depth 1 https://github.com/alisw/alidist

coverage run --source={toxinidir} -a {toxinidir}/aliBuild -a slc7_x86-64 -z test-init init zlib
coverage run --source={toxinidir} -a {toxinidir}/aliBuild -a {env:ARCHITECTURE} -z test-init init zlib
# This command is expected to fail, but run it for the coverage anyway.
# A leading "-" means tox ignores the exit code.
- coverage run --source={toxinidir} -a {toxinidir}/aliBuild build non-existing -a slc7_x86-64 --no-system --disable GCC-Toolchain
- coverage run --source={toxinidir} -a {toxinidir}/aliBuild build non-existing -a {env:ARCHITECTURE} --no-system --disable GCC-Toolchain

# TODO: do we need these? This seems to be at least partially covered by
# unit tests in tests/tests_parseRecipe.py.
Expand All @@ -93,19 +93,20 @@ commands =
sh -c 'coverage run --source={toxinidir} -a {toxinidir}/aliBuild -c {toxinidir}/tests/testdist build broken6 --force-unknown-architecture --no-system --disable GCC-Toolchain 2>&1 | tee /dev/stderr | grep "while scanning a quoted scalar"'
sh -c 'coverage run --source={toxinidir} -a {toxinidir}/aliBuild -c {toxinidir}/tests/testdist build broken7 --force-unknown-architecture --no-system --disable GCC-Toolchain 2>&1 | tee /dev/stderr | grep "Malformed entry prefer_system"'

coverage run --source={toxinidir} -a {toxinidir}/aliBuild build zlib -a slc7_x86-64 --no-system --disable GCC-Toolchain
alienv -a slc7_x86-64 q
alienv -a slc7_x86-64 setenv zlib/latest -c bash -c '[[ $LD_LIBRARY_PATH == */zlib/* ]]'
coverage run --source={toxinidir} -a {toxinidir}/aliBuild -a slc7_x86-64 doctor AliPhysics
coverage run --source={toxinidir} -a {toxinidir}/aliBuild -a slc7_x86-64 build zlib --dry-run
coverage run --source={toxinidir} -a {toxinidir}/aliBuild --aggressive-cleanup --docker -a slc7_x86-64 --always-prefer-system -d build zlib
coverage run --source={toxinidir} -a {toxinidir}/aliBuild build zlib -a {env:ARCHITECTURE} --no-system --disable GCC-Toolchain
alienv -a {env:ARCHITECTURE} q
alienv -a {env:ARCHITECTURE} setenv zlib/latest -c bash -c '[[ $LD_LIBRARY_PATH == */zlib/* ]]'
coverage run --source={toxinidir} -a {toxinidir}/aliBuild -a {env:ARCHITECTURE} doctor AliPhysics
coverage run --source={toxinidir} -a {toxinidir}/aliBuild -a {env:ARCHITECTURE} build zlib --dry-run
py311: coverage run --source={toxinidir} -a {toxinidir}/aliBuild --aggressive-cleanup --docker -a slc7_x86-64 --always-prefer-system -d build zlib
# Test for devel packages
coverage run --source={toxinidir} -a {toxinidir}/aliBuild init zlib
coverage run --source={toxinidir} -a {toxinidir}/aliBuild --aggressive-cleanup --docker -a slc7_x86-64 --always-prefer-system -d build zlib
py311: coverage run --source={toxinidir} -a {toxinidir}/aliBuild --aggressive-cleanup --docker -a slc7_x86-64 --always-prefer-system -d build zlib
# Test that we complain if we have a devel package with an untracked file
coverage run --source={toxinidir} -a {toxinidir}/aliBuild init zlib
touch zlib/foo
coverage run --source={toxinidir} -a {toxinidir}/aliBuild -a slc7_x86-64 --no-system --disable GCC-Toolchain build zlib
coverage run --source={toxinidir} -a {toxinidir}/aliBuild -a {env:ARCHITECTURE} --no-system --disable GCC-Toolchain build zlib
coverage run --source={toxinidir} -a -m unittest discover {toxinidir}/tests

[coverage:run]
branch = True
Expand Down
Loading