Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 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()
Exemplo n.º 3
0
 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"))
Exemplo n.º 4
0
 def create(self):
     """Create instance"""
     return console.HBNBCommand(stdin=self.mock_stdin,
                                stdout=self.mock_stdout)
Exemplo n.º 5
0
 def setUpClass(self):
     """Set up test"""
     self.typing = console.HBNBCommand()
Exemplo n.º 6
0
 def setUp(self):
     """Redirects stdin and stdout"""
     self.command = console.HBNBCommand()