def test_restore(self): _backupO = backups.Backups() _name = [] _backupFilename = [] # create some files and back them up for i in range(2): _name.append(self.__create_temp_file()) # do it _backupFilename.append(_backupO.backup_file(_name[i])) assert not os.path.exists(_name[i]), _name[i] assert os.path.exists(_backupFilename[i]), _backupFilename[i] for i in range(2): _backupO.restore_last_backup(_name[i]) assert os.path.exists(_name[i]), _name[i] assert not os.path.exists(_backupFilename[i]), _backupFilename[i] # try to restore the same file again try: _backupO.restore_last_backup(_name[i]) assert False, 'Restoring twice should error' except FileNotFoundError: # expected pass # Tidy up os.remove(_name[i])
def test_main_configs_in_jobs_file(self, print_): try: _backupO = backups.Backups() _backupFilename = _backupO.backup_file( TEST_PLAYER_JSON, _keep_the_original=True) # check before changes _JSNO_O = ScriptedJsonEditor.JsonRfactorFile() _player = _JSNO_O.read(TEST_PLAYER_JSON) assert _player["Graphic Options"]["Track Detail"] == 0, \ _player["Graphic Options"]["Track Detail"] assert _player["Graphic Options"]["Texture Filter"] == 0, \ _player["Graphic Options"]["Texture Filter"] sys.argv = [ 'ScriptedJsonEditor', r'Tests\jobs_test_configs.json'] _exit_code, _status = ScriptedJsonEditor.main() # check the changes were made _JSNO_O = ScriptedJsonEditor.JsonRfactorFile() _player = _JSNO_O.read(TEST_PLAYER_JSON) assert _player["Graphic Options"]["Track Detail"] == 1, \ _player["Graphic Options"]["Track Detail"] assert _player["Graphic Options"]["Texture Filter"] == 4, \ _player["Graphic Options"][""] finally: # restore the original player.JSON _backupO.restore_last_backup(TEST_PLAYER_JSON)
def test_backup(self): _name = self.__create_temp_file() # do it _backupO = backups.Backups() _backupFilename = _backupO.backup_file(_name) assert os.path.exists(_backupFilename), _backupFilename # Tidy up os.remove(_backupFilename)
def test_restore_non_existent_file(self): # try to restore a file that hasn't been backed up _backupO = backups.Backups() try: _backupO.restore_last_backup('murgle.flurgle') assert False, 'Restoring file that has not been backed up should error' except FileNotFoundError: # expected pass
def __init__(self, args, log, config, wrapper): self.log = log self.config = config self.wrapper = wrapper self.args = args self.api = api.API(wrapper, "Server", internal=True) self.backups = backups.Backups(wrapper) if "serverState" not in self.wrapper.storage: self.wrapper.storage["serverState"] = True self.players = {} self.state = 0 # 0 is off, 1 is starting, 2 is started, 3 is shutting down, 4 is idle, 5 is frozen self.bootTime = time.time() self.boot = self.wrapper.storage["serverState"] self.proc = False self.rebootWarnings = 0 self.pollSize = 0 self.data = [] if not self.wrapper.storage["serverState"]: self.log.warn( "NOTE: Server was in 'STOP' state last time Wrapper.py was running. To start the server, run /start." ) time.sleep(5) # Server Information self.worldName = None self.worldSize = 0 self.protocolVersion = -1 # -1 until proxy mode checks the server's MOTD on boot self.version = None self.world = None self.motd = None self.reloadProperties() self.api.registerEvent("irc.message", self.onChannelMessage) self.api.registerEvent("irc.action", self.onChannelAction) self.api.registerEvent("irc.join", self.onChannelJoin) self.api.registerEvent("irc.part", self.onChannelPart) self.api.registerEvent("irc.quit", self.onChannelQuit) self.api.registerEvent("timer.second", self.onTick)
def test_whole_example_job(self): sys.argv = ['ScriptedJsonEditor', 'jobs\\VR_G25.json'] try: _backupO = backups.Backups() _backupFilename = _backupO.backup_file(PLAYER_JSON, _keep_the_original=True) _backupFilename = _backupO.backup_file(CONTROLLER_JSON, _keep_the_original=True) _exit_code, _status = ScriptedJsonEditor.main() # check the changes were made _JSNO_O = ScriptedJsonEditor.JsonRfactorFile() _player = _JSNO_O.read(PLAYER_JSON) #assert _player["Graphic Options"]["Allow Letterboxing"] == False, _player["Graphic Options"]["Allow Letterboxing"] #assert _player["Graphic Options"]["Automap"] == 3, _player["Graphic Options"]["Automap"] finally: # restore the original player.JSON _backupO.restore_last_backup(PLAYER_JSON) _backupO.restore_last_backup(CONTROLLER_JSON) assert _exit_code == 0
def test_main(self, print_): # Note added , print_ to mock print() try: _backupO = backups.Backups() _backupFilename = _backupO.backup_file( TEST_PLAYER_JSON, _keep_the_original=True) # check before changes _JSNO_O = ScriptedJsonEditor.JsonRfactorFile() _player = _JSNO_O.read(TEST_PLAYER_JSON) assert _player["Graphic Options"]["Allow Letterboxing"], \ _player["Graphic Options"]["Allow Letterboxing"] assert _player["Graphic Options"]["Automap"] == 3, \ _player["Graphic Options"]["Automap"] sys.argv = ['ScriptedJsonEditor', r'Tests\jobs_test1.json'] _exit_code, _status = ScriptedJsonEditor.main() # check the changes were made _JSNO_O = ScriptedJsonEditor.JsonRfactorFile() _player = _JSNO_O.read(TEST_PLAYER_JSON) assert _player["Graphic Options"]["Allow Letterboxing"] == False, \ _player["Graphic Options"]["Allow Letterboxing"] assert _player["Graphic Options"]["Automap"] == 2, \ _player["Graphic Options"]["Automap"] finally: # restore the original player.JSON _backupO.restore_last_backup(TEST_PLAYER_JSON) assert _exit_code == 0 # Mock the print call in main() @patch('ScriptedJsonEditor.print', create=True) # Note added , print_ to mock print() def test_main_configs_in_jobs_file(self, print_): try: _backupO = backups.Backups() _backupFilename = _backupO.backup_file( TEST_PLAYER_JSON, _keep_the_original=True) # check before changes _JSNO_O = ScriptedJsonEditor.JsonRfactorFile() _player = _JSNO_O.read(TEST_PLAYER_JSON) assert _player["Graphic Options"]["Track Detail"] == 0, \ _player["Graphic Options"]["Track Detail"] assert _player["Graphic Options"]["Texture Filter"] == 0, \ _player["Graphic Options"]["Texture Filter"] sys.argv = [ 'ScriptedJsonEditor', r'Tests\jobs_test_configs.json'] _exit_code, _status = ScriptedJsonEditor.main() # check the changes were made _JSNO_O = ScriptedJsonEditor.JsonRfactorFile() _player = _JSNO_O.read(TEST_PLAYER_JSON) assert _player["Graphic Options"]["Track Detail"] == 1, \ _player["Graphic Options"]["Track Detail"] assert _player["Graphic Options"]["Texture Filter"] == 4, \ _player["Graphic Options"][""] finally: # restore the original player.JSON _backupO.restore_last_backup(TEST_PLAYER_JSON) assert _exit_code == 0