|
| 1 | +"""Tests for main.py.""" |
| 2 | +# pylint: disable=import-error, wrong-import-position, unused-argument, line-too-long |
| 3 | + |
| 4 | +import sys |
| 5 | +import os |
| 6 | +from unittest.mock import patch, call |
| 7 | + |
| 8 | +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 9 | + |
| 10 | +import main |
| 11 | + |
| 12 | + |
| 13 | +@patch("builtins.input", side_effect=["newpiece", "Brick", "Red", "5"]) |
| 14 | +@patch("builtins.print") |
| 15 | +def test_lego_cmd_newpiece(self, mock_print): |
| 16 | + """Test the newpiece command.""" |
| 17 | + main.lego_cmd() |
| 18 | + mock_print.assert_has_calls( |
| 19 | + [ |
| 20 | + call("LEGO CMD: "), |
| 21 | + call("Name the piece you would like to add: "), |
| 22 | + call( |
| 23 | + 'What is the piece colour (make sure this colour is in the colour database, otherwise add using "newcolour")? ' |
| 24 | + ), |
| 25 | + call("How many of that would you like to add? "), |
| 26 | + ] |
| 27 | + ) |
| 28 | + |
| 29 | + |
| 30 | +@patch("builtins.input", side_effect=["newcolour", "Red"]) |
| 31 | +@patch("builtins.print") |
| 32 | +def test_lego_cmd_newcolour(self, mock_print): |
| 33 | + """Test the newcolour command.""" |
| 34 | + main.lego_cmd() |
| 35 | + mock_print.assert_has_calls( |
| 36 | + [ |
| 37 | + call("LEGO CMD: "), |
| 38 | + call("Name the colour you would like to add: "), |
| 39 | + ] |
| 40 | + ) |
| 41 | + |
| 42 | + |
| 43 | +@patch("builtins.input", side_effect=["newcolor", "Red"]) |
| 44 | +@patch("builtins.print") |
| 45 | +def test_lego_cmd_newcolor(self, mock_print): |
| 46 | + """Test the newcolor command.""" |
| 47 | + main.lego_cmd() |
| 48 | + mock_print.assert_has_calls( |
| 49 | + [ |
| 50 | + call("LEGO CMD: "), |
| 51 | + call("Name the color you would like to add: "), |
| 52 | + ] |
| 53 | + ) |
| 54 | + |
| 55 | + |
| 56 | +@patch("builtins.input", side_effect=["addpiece", "Brick", "Red", "5"]) |
| 57 | +@patch("builtins.print") |
| 58 | +def test_lego_cmd_addpiece(self, mock_print): |
| 59 | + """Test the addpiece command.""" |
| 60 | + main.lego_cmd() |
| 61 | + mock_print.assert_has_calls( |
| 62 | + [ |
| 63 | + call("LEGO CMD: "), |
| 64 | + call("What is the name of the piece that you would like to add to? "), |
| 65 | + call("What is the piece colour? "), |
| 66 | + call("How many of that piece do you want to add? "), |
| 67 | + ] |
| 68 | + ) |
| 69 | + |
| 70 | + |
| 71 | +@patch("builtins.input", side_effect=["removepiece", "Brick", "Red", "5"]) |
| 72 | +@patch("builtins.print") |
| 73 | +def test_lego_cmd_removepiece(self, mock_print): |
| 74 | + """Test the removepiece command.""" |
| 75 | + main.lego_cmd() |
| 76 | + mock_print.assert_has_calls( |
| 77 | + [ |
| 78 | + call("LEGO CMD: "), |
| 79 | + call("What is the name of the piece that you would like to remove? "), |
| 80 | + call("What is the piece colour? "), |
| 81 | + call("How many of that piece do you want to remove? "), |
| 82 | + ] |
| 83 | + ) |
| 84 | + |
| 85 | + |
| 86 | +@patch( |
| 87 | + "builtins.input", |
| 88 | + side_effect=["newset", "Police Station", "123456", "City", "100", "5"], |
| 89 | +) |
| 90 | +@patch("builtins.print") |
| 91 | +def test_lego_cmd_newset(self, mock_print): |
| 92 | + """Test the newset command.""" |
| 93 | + main.lego_cmd() |
| 94 | + mock_print.assert_has_calls( |
| 95 | + [ |
| 96 | + call("LEGO CMD: "), |
| 97 | + call("Name the set you would like to add: "), |
| 98 | + call("What is the set number for the set you would like to add? "), |
| 99 | + call( |
| 100 | + 'What is the theme for the set you would like to add? \ |
| 101 | + (make sure this theme is in the database, \ |
| 102 | + otherwise add using "newtheme") ' |
| 103 | + ), |
| 104 | + call("How many pieces are there in this set? "), |
| 105 | + call("How many of this set would you like to add? "), |
| 106 | + ] |
| 107 | + ) |
| 108 | + |
| 109 | + |
| 110 | +@patch("builtins.input", side_effect=["newtheme", "City"]) |
| 111 | +@patch("builtins.print") |
| 112 | +def test_lego_cmd_newtheme(self, mock_print): |
| 113 | + """Test the newtheme command.""" |
| 114 | + main.lego_cmd() |
| 115 | + mock_print.assert_has_calls( |
| 116 | + [ |
| 117 | + call("LEGO CMD: "), |
| 118 | + call("Name the theme you would like to add: "), |
| 119 | + ] |
| 120 | + ) |
| 121 | + |
| 122 | + |
| 123 | +@patch("builtins.input", side_effect=["addset", "123456", "5"]) |
| 124 | +@patch("builtins.print") |
| 125 | +def test_lego_cmd_addset(self, mock_print): |
| 126 | + """Test the addset command.""" |
| 127 | + main.lego_cmd() |
| 128 | + mock_print.assert_has_calls( |
| 129 | + [ |
| 130 | + call("LEGO CMD: "), |
| 131 | + call("What is the set number of the set that you would like to add? "), |
| 132 | + call("How many of that set do you want to add? "), |
| 133 | + ] |
| 134 | + ) |
| 135 | + |
| 136 | + |
| 137 | +@patch("builtins.input", side_effect=["removeset", "123456", "5"]) |
| 138 | +@patch("builtins.print") |
| 139 | +def test_lego_cmd_removeset(self, mock_print): |
| 140 | + """Test the removeset command.""" |
| 141 | + main.lego_cmd() |
| 142 | + mock_print.assert_has_calls( |
| 143 | + [ |
| 144 | + call("LEGO CMD: "), |
| 145 | + call("What is the set number of the set that you would like to remove? "), |
| 146 | + call("How many of that set do you want to remove? "), |
| 147 | + ] |
| 148 | + ) |
0 commit comments