Пример #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)
Пример #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()
Пример #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"))
Пример #4
0
 def create(self):
     """Create instance"""
     return console.HBNBCommand(stdin=self.mock_stdin,
                                stdout=self.mock_stdout)
Пример #5
0
 def setUpClass(self):
     """Set up test"""
     self.typing = console.HBNBCommand()
Пример #6
0
 def setUp(self):
     """Redirects stdin and stdout"""
     self.command = console.HBNBCommand()