Exemplo n.º 1
0
 def test_save_and_load(self):
     # temporary file to save data
     (file1,filepath1) = tempfile.mkstemp(suffix='.tmp', prefix='thermod')
     (file2,filepath2) = tempfile.mkstemp(suffix='.tmp', prefix='thermod')
     
     # timetable has no filepath cannot be saved
     self.assertRaises(RuntimeError,self.timetable.save)
     
     # setting filepath
     self.timetable.filepath = filepath1
     
     # timetable is empty cannot be saved
     self.assertRaises(ValidationError,self.timetable.save)
     
     # filling the timetable
     fill_timetable(self.timetable)
     
     # saving and loading two times
     self.timetable.save()
     tt1 = TimeTable(filepath1)
     self.assertEqual(self.timetable, tt1)
     self.assertEqual(self.timetable.mode, tt1.mode)
     
     tt1.save(filepath2)
     tt2 = TimeTable()
     tt2.filepath = filepath2
     tt2.reload()
     self.assertEqual(self.timetable, tt2)
     self.assertEqual(self.timetable.mode, tt2.mode)
     
     # removing temporary files
     os.close(file1)
     os.remove(filepath1)
     os.close(file2)
     os.remove(filepath2)
Exemplo n.º 2
0
 def test_equality_and_copy_operators(self):
     tt = TimeTable()
     
     fill_timetable(self.timetable)
     fill_timetable(tt)
     
     self.assertEqual(self.timetable, tt)
     self.assertEqual(self.timetable.mode, tt.mode)
     
     # test copy operators
     tt2 = copy.deepcopy(self.timetable)
     self.assertEqual(self.timetable, tt2)
     self.assertEqual(self.timetable.mode, tt2.mode)
     
     # changing the mode makes two timetable different
     tt2.mode = timetable.JSON_MODE_OFF
     self.assertNotEqual(self.timetable, tt2)
     self.assertNotEqual(self.timetable.mode, tt2.mode)
     
     # change other settings and test inequality
     tt.hvac_mode = timetable.JSON_HVAC_COOLING
     self.assertNotEqual(self.timetable, tt)
     self.assertNotEqual(self.timetable.hvac_mode, tt.hvac_mode)
     
     tt2.update(3,15,0,34)
     self.assertNotEqual(self.timetable, tt2)
Exemplo n.º 3
0
    def setUp(self):
        self.timetable = TimeTable()
        fill_timetable(self.timetable)

        self.mttable = MementoTable()
        fill_timetable(self.mttable)

        self.heating = BaseHeating()
Exemplo n.º 4
0
 def test_equality_regardless_of_inertia(self):
     tt = TimeTable(inertia=1)
     
     fill_timetable(self.timetable)
     fill_timetable(tt)
     
     self.assertEqual(self.timetable, tt)
     
     # now change inertia
     tt._inertia = 2
     self.assertEqual(self.timetable, tt)
 
     # now change again
     tt._inertia = 3
     self.assertEqual(self.timetable, tt)
Exemplo n.º 5
0
 async def this_test():
     async with aiohttp.ClientSession() as session:
         # wrong url
         async with session.get('http://localhost:4345/wrong') as wrong:
             self.assertEqual(wrong.status, 404)
         
         # right url
         async with session.get(__url_settings__) as r:
             self.assertEqual(r.status, 200)
             settings = await r.json()
         
         # check returned settings
         tt = TimeTable()
         tt.__setstate__(settings)
         self.assertEqual(self.timetable, tt)
Exemplo n.º 6
0
    def setUp(self):
        self.lock = asyncio.Condition()

        self.timetable = TimeTable()
        fill_timetable(self.timetable)
        self.timetable.filepath = os.path.join(tempfile.gettempdir(),
                                               'timetable.json')
        self.timetable.save()

        self.heating = BaseHeating()
        self.cooling = BaseCooling()
        self.thermometer = FakeThermometer()

        self.socket = SocketThread(self.timetable, self.heating, self.cooling,
                                   self.thermometer, self.lock)
        self.socket.start()
Exemplo n.º 7
0
    def test_get_settings(self):
        # wrong url
        wrong = requests.get('http://localhost:4345/wrong')
        self.assertEqual(wrong.status_code, 404)
        wrong.close()

        # right url
        r = requests.get(__url_settings__)
        self.assertEqual(r.status_code, 200)
        settings = r.json()
        r.close()

        # check returned settings
        tt = TimeTable()
        tt.__setstate__(settings)
        self.assertEqual(self.timetable, tt)
Exemplo n.º 8
0
 def setUp(self):
     self.loop = asyncio.get_event_loop()
     self.lock = asyncio.Condition()
     
     self.timetable = TimeTable()
     fill_timetable(self.timetable)
     self.timetable.filepath = os.path.join(tempfile.gettempdir(), 'timetable.json')
     self.timetable.save()
     
     self.heating = BaseHeating()
     self.thermometer = FakeThermometer()
     
     self.socket = ControlSocket(self.timetable,
                                 self.heating,
                                 self.thermometer,
                                 'localhost',
                                 4345,  # using different port to run test while real thermod is running
                                 self.lock)
     self.loop.run_until_complete(self.socket.start())
Exemplo n.º 9
0
 def setUp(self):
     self.timetable = TimeTable()
     self.heating = BaseHeating()