def test_ReadFile(self): parsedJson = { 1: [[ 1, 'accusamus beatae ad facilis cum similique qui sunt', 'https://via.placeholder.com/600/92c952', 'https://via.placeholder.com/150/92c952' ]] } self.assertEqual(parsedJson, readFile(jsonFileCheck("test1.json")), "ReadFile check")
def testJsonFileCheck(self): self.assertEqual([{ 'test': 'passed' }], jsonFileCheck("test.json"), ".json file check")
def test_StandardOutput_Object(self, mock_stdout): photoAlbums = createObjects(jsonFileCheck("test1.json")) photoAlbums[1].displayContents() excpectedOut = '\nPhoto Album 1 contains:\n\n[1] accusamus beatae ad facilis cum similique qui sunt\n' self.assertEqual(mock_stdout.getvalue(), excpectedOut)
def test_StandardOutput_Non_Object(self, mock_stdout): file = readFile(jsonFileCheck("test1.json")) printFile(file, 1) excpectedOut = '\nPhoto Album 1 contains:\n\n[1] accusamus beatae ad facilis cum similique qui sunt\n' self.assertEqual(mock_stdout.getvalue(), excpectedOut)
def test_JsonFile_Repeated_BadInput_Quit(self): userInput = ["na", "none", "nothing", "quit"] with mock.patch('builtins.input', side_effect=userInput): with self.assertRaises(SystemExit) as cm: jsonFileCheck("nonsense") self.assertEqual(cm.exception.code, 0)
def testJson_File_Repeated_Bad_Input(self): userInput = ["na", "none", "nothing", "test.json"] with mock.patch('builtins.input', side_effect=userInput): answer = jsonFileCheck("nonsense") self.assertEqual([{"test": "passed"}], answer)