Skip to content

Commit

Permalink
test_build.py: refactor test_build_complete1
Browse files Browse the repository at this point in the history
  • Loading branch information
Obijuan committed Feb 21, 2024
1 parent 99f0ee1 commit a46cd83
Showing 1 changed file with 143 additions and 105 deletions.
248 changes: 143 additions & 105 deletions test/code_commands/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,238 +2,276 @@
Test for the "apio build" command
"""

#-- This is for testing "apio build"
# -- This is for testing "apio build"
from apio.commands.build import cli as cmd_build

#-- This is for testing "apio init"
# -- This is for testing "apio init"
from apio.commands.init import cli as cmd_init


def test_build(clirunner, configenv):
"""Test: apio build
when no apio.ini file is given
No additional parameters are given
when no apio.ini file is given
No additional parameters are given
"""

with clirunner.isolated_filesystem():

#-- Config the environment (conftest.configenv())
# -- Config the environment (conftest.configenv())
configenv()

#-- Execute "apio build"
# -- Execute "apio build"
result = clirunner.invoke(cmd_build)

#-- It is an error. Exit code should not be 0
# -- It is an error. Exit code should not be 0
assert result.exit_code != 0

#-- Messages thtat should appear
assert 'Info: No apio.ini file' in result.output
assert 'Error: insufficient arguments: missing board' in result.output
assert 'Error: Missing FPGA' in result.output
# -- Messages thtat should appear
assert "Info: No apio.ini file" in result.output
assert "Error: insufficient arguments: missing board" in result.output
assert "Error: Missing FPGA" in result.output


def test_build_board(clirunner, configenv):
"""Test: apio build --board icezum
No oss-cad-suite package is installed
No oss-cad-suite package is installed
"""

with clirunner.isolated_filesystem():

#-- Config the environment (conftest.configenv())
# -- Config the environment (conftest.configenv())
configenv()

#-- Execute "apio build --board icezum"
result = clirunner.invoke(cmd_build, ['--board', 'icezum'])
# -- Execute "apio build --board icezum"
result = clirunner.invoke(cmd_build, ["--board", "icezum"])

#-- It is an error. Exit code should not be 0
# -- It is an error. Exit code should not be 0
assert result.exit_code != 0

#-- Error code 1 means the install oss-cad-suite package
#-- is not installed
# -- Error code 1 means the install oss-cad-suite package
# -- is not installed
if result.exit_code == 1:
assert 'install oss-cad-suite' in result.output
assert "install oss-cad-suite" in result.output


def test_build_complete1(clirunner, configenv):
"""Test: apio build with different arguments. Part 1/2"""

with clirunner.isolated_filesystem():

#-- Config the environment (conftest.configenv())
# -- Config the environment (conftest.configenv())
configenv()

# apio build --board icestick
result = clirunner.invoke(cmd_build, ['--board', 'icestick'])
result = clirunner.invoke(cmd_build, ["--board", "icestick"])
assert result.exit_code == 1
assert 'install oss-cad-suite' in result.output
assert "install oss-cad-suite" in result.output

# apio build --fpga iCE40-HX1K-VQ100
result = clirunner.invoke(cmd_build, ['--fpga', 'iCE40-HX1K-VQ100'])
result = clirunner.invoke(cmd_build, ["--fpga", "iCE40-HX1K-VQ100"])
assert result.exit_code == 1
assert 'install oss-cad-suite' in result.output
assert "install oss-cad-suite" in result.output

# TODO
# apio build --type lp --size 8k --pack cm225:4k
result = clirunner.invoke(cmd_build, [
'--type', 'lp', '--size', '8k', '--pack', 'cm225:4k'])
assert result.exit_code != 0
result = clirunner.invoke(
cmd_build, ["--type", "lp", "--size", "8k", "--pack", "cm225:4k"]
)
assert result.exit_code == 1
assert "Error: insufficient arguments" in result.output

# apio build --board icezum --size 1k
result = clirunner.invoke(cmd_build, [
'--board', 'icezum', '--size', '1k'])
result = clirunner.invoke(
cmd_build, ["--board", "icezum", "--size", "1k"]
)
assert result.exit_code != 0
#assert 'Warning: redundant arguments: size' in result.output
assert "install oss-cad-suite" in result.output

# apio build --board icezum --fpga iCE40-HX1K-TQ144 --type hx
result = clirunner.invoke(cmd_build, [
'--board', 'icezum', '--fpga', 'iCE40-HX1K-TQ144', '--type', 'hx'])
result = clirunner.invoke(
cmd_build,
[
"--board",
"icezum",
"--fpga",
"iCE40-HX1K-TQ144",
"--type",
"hx",
],
)
assert result.exit_code != 0
#assert 'Warning: redundant arguments: fpga, type' in result.output
assert "install oss-cad-suite" in result.output

# apio build --board icezum --pack tq144
result = clirunner.invoke(cmd_build, [
'--board', 'icezum', '--pack', 'tq144'])
result = clirunner.invoke(
cmd_build, ["--board", "icezum", "--pack", "tq144"]
)
assert result.exit_code != 0
#assert 'Warning: redundant arguments: pack' in result.output
assert "install oss-cad-suite" in result.output

# apio build --fpga iCE40-HX1K-TQ144 --pack tq144 --size 1k
result = clirunner.invoke(cmd_build, [
'--fpga', 'iCE40-HX1K-TQ144', '--pack', 'tq144', '--size', '1k'])
result = clirunner.invoke(
cmd_build,
["--fpga", "iCE40-HX1K-TQ144", "--pack", "tq144", "--size", "1k"],
)
assert result.exit_code != 0
#assert 'Warning: redundant arguments: size, pack' in result.output
assert "install oss-cad-suite" in result.output

# apio build --fpga iCE40-HX1K-TQ144 --type hx
result = clirunner.invoke(cmd_build, [
'--fpga', 'iCE40-HX1K-TQ144', '--type', 'hx'])
result = clirunner.invoke(
cmd_build, ["--fpga", "iCE40-HX1K-TQ144", "--type", "hx"]
)
assert result.exit_code != 0
#assert 'Warning: redundant arguments: type' in result.output
assert "install oss-cad-suite" in result.output

# apio build --board icezum --size 8k
result = clirunner.invoke(cmd_build, [
'--board', 'icezum', '--size', '8k'])
result = clirunner.invoke(
cmd_build, ["--board", "icezum", "--size", "8k"]
)
assert result.exit_code != 0
#assert 'Error: contradictory arguments: size' in result.output
assert "Error: contradictory arguments: ('1k', '8k')" in result.output

# apio build --board icezum --fpga iCE40-HX1K-TQ144 --type lp
result = clirunner.invoke(cmd_build, [
'--board', 'icezum', '--fpga', 'iCE40-HX1K-TQ144', '--type', 'lp'])
result = clirunner.invoke(
cmd_build,
[
"--board",
"icezum",
"--fpga",
"iCE40-HX1K-TQ144",
"--type",
"lp",
],
)
assert result.exit_code != 0
#assert 'Warning: redundant arguments: fpga' in result.output
#assert 'Error: contradictory arguments: type' in result.output
assert "Error: contradictory arguments: ('hx', 'lp')" in result.output

# apio build --board icezum --fpga iCE40-HX1K-VQ100
result = clirunner.invoke(cmd_build, [
'--board', 'icezum', '--fpga', 'iCE40-HX1K-VQ100'])
result = clirunner.invoke(
cmd_build, ["--board", "icezum", "--fpga", "iCE40-HX1K-VQ100"]
)
assert result.exit_code != 0
assert 'Error: contradictory arguments:' in result.output
#assert 'Error: contradictory arguments: fpga' in result.output
assert (
"Error: contradictory arguments: ('iCE40-HX1K-TQ144', "
"'iCE40-HX1K-VQ100')" in result.output
)

# apio build --fpga iCE40-HX1K-TQ144 --type lp --size 8k
result = clirunner.invoke(cmd_build, [
'--fpga', 'iCE40-HX1K-TQ144', '--type', 'lp', '--size', '8k'])
result = clirunner.invoke(
cmd_build,
["--fpga", "iCE40-HX1K-TQ144", "--type", "lp", "--size", "8k"],
)
assert result.exit_code != 0
#assert 'Error: contradictory arguments: size, type' in result.output
assert "Error: contradictory arguments: ('hx', 'lp')" in result.output

# apio build --fpga iCE40-HX1K-TQ144 --pack vq100
result = clirunner.invoke(cmd_build, [
'--fpga', 'iCE40-HX1K-TQ144', '--pack', 'vq100'])
result = clirunner.invoke(
cmd_build, ["--fpga", "iCE40-HX1K-TQ144", "--pack", "vq100"]
)
assert result.exit_code != 0
#assert 'Error: contradictory arguments: pack' in result.output
assert (
"Error: contradictory arguments: ('tq144', 'vq100')"
in result.output
)

# apio build --board icezum --pack vq100
result = clirunner.invoke(cmd_build, [
'--board', 'icezum', '--pack', 'vq100'])
result = clirunner.invoke(
cmd_build, ["--board", "icezum", "--pack", "vq100"]
)
assert result.exit_code != 0
#assert 'Error: contradictory arguments: pack' in result.output
assert (
"Error: contradictory arguments: ('tq144', 'vq100')"
in result.output
)

# apio build --size 8k
result = clirunner.invoke(cmd_build, ['--size', '8k'])
assert result.exit_code != 0
#assert 'Error: insufficient arguments: missing type, pack' \
# in result.output

# apio build --type lp
result = clirunner.invoke(cmd_build, ['--type', 'lp'])
assert result.exit_code != 0
#assert 'Error: insufficient arguments: missing size, pack' \
# in result.output

# apio build --type lp --size 8k
result = clirunner.invoke(cmd_build, ['--type', 'lp', '--size', '8k'])
result = clirunner.invoke(cmd_build, ["--size", "8k"])
assert result.exit_code != 0
#assert 'Error: insufficient arguments: missing pack' in result.output
assert "Error: insufficient arguments" in result.output


def test_build_complete2(clirunner, configenv):
"""Test: apio build with different arguments. Part 2/2"""

with clirunner.isolated_filesystem():

#-- Config the environment (conftest.configenv())
# -- Config the environment (conftest.configenv())
configenv()

# apio build --type lp
result = clirunner.invoke(cmd_build, ["--type", "lp"])
assert result.exit_code != 0
assert "Error: insufficient arguments" in result.output

# apio build --type lp --size 8k
result = clirunner.invoke(cmd_build, ["--type", "lp", "--size", "8k"])
assert result.exit_code != 0
assert "Error: insufficient arguments" in result.output

# apio build --board icefake
result = clirunner.invoke(cmd_build, ['--board', 'icefake'])
result = clirunner.invoke(cmd_build, ["--board", "icefake"])
assert result.exit_code != 0
assert 'Error: unknown board: icefake' in result.output
assert "Error: unknown board: icefake" in result.output

# apio build --board icefake --fpga iCE40-HX1K-TQ144
result = clirunner.invoke(cmd_build, [
'--board', 'icefake', '--fpga', 'iCE40-HX1K-TQ144'])
result = clirunner.invoke(
cmd_build, ["--board", "icefake", "--fpga", "iCE40-HX1K-TQ144"]
)
assert result.exit_code != 0
assert 'Error: unknown board: icefake' in result.output
assert "Error: unknown board: icefake" in result.output

# apio build --fpga iCE40-FAKE
result = clirunner.invoke(cmd_build, ['--fpga', 'iCE40-FAKE'])
result = clirunner.invoke(cmd_build, ["--fpga", "iCE40-FAKE"])
assert result.exit_code != 0
#assert 'Error: unknown FPGA: iCE40-FAKE' in result.output
# assert 'Error: unknown FPGA: iCE40-FAKE' in result.output

# apio build --fpga iCE40-FAKE --size 8k
result = clirunner.invoke(cmd_build, [
'--fpga', 'iCE40-FAKE', '--size', '8k'])
result = clirunner.invoke(
cmd_build, ["--fpga", "iCE40-FAKE", "--size", "8k"]
)
assert result.exit_code != 0
#assert 'Error: unknown FPGA: iCE40-FAKE' in result.output
# assert 'Error: unknown FPGA: iCE40-FAKE' in result.output

# apio build --board icezum --fpga iCE40-FAKE
result = clirunner.invoke(cmd_build, [
'--board', 'icezum', '--fpga', 'iCE40-FAKE'])
result = clirunner.invoke(
cmd_build, ["--board", "icezum", "--fpga", "iCE40-FAKE"]
)
assert result.exit_code != 0
#assert 'Error: unknown FPGA: iCE40-FAKE' in result.output

# assert 'Error: unknown FPGA: iCE40-FAKE' in result.output


def test_build_init(clirunner, configenv):
with clirunner.isolated_filesystem():
configenv()

# apio init --board icezum
result = clirunner.invoke(cmd_init, ['--board', 'icezum'])
result = clirunner.invoke(cmd_init, ["--board", "icezum"])
assert result.exit_code == 0
assert 'Creating apio.ini file ...' in result.output
assert 'has been successfully created!' in result.output
assert "Creating apio.ini file ..." in result.output
assert "has been successfully created!" in result.output

# apio build
result = clirunner.invoke(cmd_build)
assert result.exit_code != 0

# apio build --board icezum
result = clirunner.invoke(cmd_build, ['--board', 'icestick'])
result = clirunner.invoke(cmd_build, ["--board", "icestick"])
assert result.exit_code != 0
assert 'Info: ignore apio.ini board' in result.output
assert "Info: ignore apio.ini board" in result.output

# apio build --fpga iCE40-HX1K-VQ100
result = clirunner.invoke(cmd_build, ['--fpga', 'iCE40-HX1K-VQ100'])
result = clirunner.invoke(cmd_build, ["--fpga", "iCE40-HX1K-VQ100"])
assert result.exit_code != 0
#assert 'Info: ignore apio.ini board' in result.output
# assert 'Info: ignore apio.ini board' in result.output

# apio build --type lp --size 8k --pack cm225:4k
result = clirunner.invoke(cmd_build, [
'--type', 'lp', '--size', '8k', '--pack', 'cm225:4k'])
result = clirunner.invoke(
cmd_build, ["--type", "lp", "--size", "8k", "--pack", "cm225:4k"]
)
assert result.exit_code != 0
#assert 'Info: ignore apio.ini board' in result.output
# assert 'Info: ignore apio.ini board' in result.output

# apio build --type lp --size 8k
result = clirunner.invoke(cmd_build, ['--type', 'lp', '--size', '8k'])
result = clirunner.invoke(cmd_build, ["--type", "lp", "--size", "8k"])
assert result.exit_code != 0
#assert 'Info: ignore apio.ini board' in result.output
#assert 'Error: insufficient arguments: missing pack' in result.output
# assert 'Info: ignore apio.ini board' in result.output
# assert 'Error: insufficient arguments: missing pack' in result.output

0 comments on commit a46cd83

Please sign in to comment.