def setUpClass(cls): """Create the console and hook it up to a StringIO input and output""" if os.path.exists('storage.json'): os.remove('storage.json') TestConsole.i = io.StringIO() TestConsole.o = io.StringIO() TestConsole.cmd = console.HBNBCommand(stdin=TestConsole.i, stdout=TestConsole.o) TestConsole.cmd._HBNBCommand__print = \ functools.partial(print, file=TestConsole.cmd.stdout)
def test_create(self): """Tests well-behaved create commands. Assumes correct uuid output""" f = open("./tests/increatetest.txt", "r") cmdp = console.HBNBCommand(stdin=f, stdout=outbuffer) cmdp.use_rawinput = False cmdp.prompt = "" with redirect_stdout(outbuffer): cmdp.cmdloop() f.close() ids = outbuffer.getvalue() ids = ids.split("\n") objects = storage.all()
def test_showbad(self): """Test bad show commands""" self.maxDiff = None shutil.copy("./tests/allfile.json", "./file.json") teststore = FileStorage() teststore.reload() outbuffer = io.StringIO() f = open("./tests/inshowbadtest.txt", "r") cmdp = console.HBNBCommand(stdin=f, stdout=outbuffer) cmdp.use_rawinput = False cmdp.prompt = "" with redirect_stdout(outbuffer): cmdp.cmdloop() f.close() g = open("./tests/inshowbadresult.txt") self.assertEqual(g.read(), outbuffer.getvalue()) g.close() teststore.save() self.assertEqual(json.load("./tests/allfile.json"), json.load("./file.json"))
def create(self): """Create instance""" return console.HBNBCommand(stdin=self.mock_stdin, stdout=self.mock_stdout)
def setUpClass(self): """Set up test""" self.typing = console.HBNBCommand()
def setUp(self): """Redirects stdin and stdout""" self.command = console.HBNBCommand()