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

Unit tests for RecipeTypes.py #288

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
117 changes: 117 additions & 0 deletions tests/test_recipetypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
"""Unit tests for RecipeTypes.py"""
from HaikuPorter.RecipeTypes import Architectures, MachineArchitecture, Phase, YesNo
from pytest import mark

# Constant test assets necessary for testing
_ARCHITECTURE_LIST = [
"arm",
"arm64",
"m68k",
"ppc",
"riscv64",
"sparc",
"sparc64",
"x86",
"x86_64",
"x86_gcc2",
"unknown_arch",
]

_EXPECTED_ARCHITECTURES_LIST = [
"arm",
"arm64",
"m68k",
"ppc",
"riscv64",
"sparc",
"x86",
"x86_64",
"x86_gcc2",
"any",
"source",
]

_EXPECTED_ARCHITECTURE_LIST = [
"arm",
"arm64",
"m68k",
"ppc",
"riscv64",
"sparc",
"sparc",
"x86",
"x86_64",
"x86_gcc2",
None,
]

_TRIPLETS_LIST = [
"arm-unknown-haiku",
"aarch64-unknown-haiku",
"m68k-unknown-haiku",
"powerpc-apple-haiku",
"riscv64-unknown-haiku",
"sparc64-unknown-haiku",
None, # necessary for findMath() testing
"i586-pc-haiku",
"x86_64-unknown-haiku",
"i586-pc-haiku",
None,
]


# MachineArchitecture tests
def test_machinearchitecture_getall_positive():
"""UT for getAll() - positive test case."""
assert MachineArchitecture.getAll() == [
"arm",
"arm64",
"m68k",
"ppc",
"riscv64",
"sparc",
"x86",
"x86_64",
"x86_gcc2",
]


def test_machinearchitecture_gettriplefor_positive():
"""UT for getTripleFor() - positive test case."""
for index, value in enumerate(_ARCHITECTURE_LIST):
assert MachineArchitecture.getTripleFor(value) == _TRIPLETS_LIST[index]


def test_machinearchitecture_findmatch_positive():
"""UT for findMatch() - positive test case."""
for index, value in enumerate(_ARCHITECTURE_LIST):
assert (
MachineArchitecture.findMatch(value) == _EXPECTED_ARCHITECTURE_LIST[index]
)


# YesNo tests
def test_yesno_getallowedvalues():
"""UT for getAllowedValues() - positive test case."""
assert YesNo.getAllowedValues() == ["yes", "no", "true", "false"]


@mark.parametrize(
"value, expected_response",
[["yes", True], ["tRue", True], ["no", False], ["false", False]],
)
def test_yesno_tobool(value, expected_response):
"""UT for toBool() - positive test case."""
assert YesNo.toBool(value) == expected_response


# Phase tests
def test_phase_getallowedvalues():
"""UT for getAllowedValues() - positive test case."""
assert Phase.getAllowedValues() == ["PATCH", "BUILD", "TEST", "INSTALL"]


# Architectures tests
def test_architectures_getall():
"""UT for getAll() - positive test case."""
assert Architectures.getAll() == _EXPECTED_ARCHITECTURES_LIST
Loading