Skip to content

Add testing files #124

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

Merged
merged 2 commits into from
Dec 7, 2023
Merged
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
22 changes: 22 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: PyTest

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: pytest

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Project Requirements

pytest
148 changes: 148 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"""Tests for main.py."""
# pylint: disable=import-error, wrong-import-position, unused-argument, line-too-long

import sys
import os
from unittest.mock import patch, call

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import main


@patch("builtins.input", side_effect=["newpiece", "Brick", "Red", "5"])
@patch("builtins.print")
def test_lego_cmd_newpiece(self, mock_print):
"""Test the newpiece command."""
main.lego_cmd()
mock_print.assert_has_calls(
[
call("LEGO CMD: "),
call("Name the piece you would like to add: "),
call(
'What is the piece colour (make sure this colour is in the colour database, otherwise add using "newcolour")? '
),
call("How many of that would you like to add? "),
]
)


@patch("builtins.input", side_effect=["newcolour", "Red"])
@patch("builtins.print")
def test_lego_cmd_newcolour(self, mock_print):
"""Test the newcolour command."""
main.lego_cmd()
mock_print.assert_has_calls(
[
call("LEGO CMD: "),
call("Name the colour you would like to add: "),
]
)


@patch("builtins.input", side_effect=["newcolor", "Red"])
@patch("builtins.print")
def test_lego_cmd_newcolor(self, mock_print):
"""Test the newcolor command."""
main.lego_cmd()
mock_print.assert_has_calls(
[
call("LEGO CMD: "),
call("Name the color you would like to add: "),
]
)


@patch("builtins.input", side_effect=["addpiece", "Brick", "Red", "5"])
@patch("builtins.print")
def test_lego_cmd_addpiece(self, mock_print):
"""Test the addpiece command."""
main.lego_cmd()
mock_print.assert_has_calls(
[
call("LEGO CMD: "),
call("What is the name of the piece that you would like to add to? "),
call("What is the piece colour? "),
call("How many of that piece do you want to add? "),
]
)


@patch("builtins.input", side_effect=["removepiece", "Brick", "Red", "5"])
@patch("builtins.print")
def test_lego_cmd_removepiece(self, mock_print):
"""Test the removepiece command."""
main.lego_cmd()
mock_print.assert_has_calls(
[
call("LEGO CMD: "),
call("What is the name of the piece that you would like to remove? "),
call("What is the piece colour? "),
call("How many of that piece do you want to remove? "),
]
)


@patch(
"builtins.input",
side_effect=["newset", "Police Station", "123456", "City", "100", "5"],
)
@patch("builtins.print")
def test_lego_cmd_newset(self, mock_print):
"""Test the newset command."""
main.lego_cmd()
mock_print.assert_has_calls(
[
call("LEGO CMD: "),
call("Name the set you would like to add: "),
call("What is the set number for the set you would like to add? "),
call(
'What is the theme for the set you would like to add? \
(make sure this theme is in the database, \
otherwise add using "newtheme") '
),
call("How many pieces are there in this set? "),
call("How many of this set would you like to add? "),
]
)


@patch("builtins.input", side_effect=["newtheme", "City"])
@patch("builtins.print")
def test_lego_cmd_newtheme(self, mock_print):
"""Test the newtheme command."""
main.lego_cmd()
mock_print.assert_has_calls(
[
call("LEGO CMD: "),
call("Name the theme you would like to add: "),
]
)


@patch("builtins.input", side_effect=["addset", "123456", "5"])
@patch("builtins.print")
def test_lego_cmd_addset(self, mock_print):
"""Test the addset command."""
main.lego_cmd()
mock_print.assert_has_calls(
[
call("LEGO CMD: "),
call("What is the set number of the set that you would like to add? "),
call("How many of that set do you want to add? "),
]
)


@patch("builtins.input", side_effect=["removeset", "123456", "5"])
@patch("builtins.print")
def test_lego_cmd_removeset(self, mock_print):
"""Test the removeset command."""
main.lego_cmd()
mock_print.assert_has_calls(
[
call("LEGO CMD: "),
call("What is the set number of the set that you would like to remove? "),
call("How many of that set do you want to remove? "),
]
)