def test_main_key_error_in_jobs_file(self, print_): _JSNO_O = ScriptedJsonEditor.JsonFile() try: _jobs = _JSNO_O._load( test_test_strings.jobsJSONstrBadKey, 'test_test_strings.jobsJSONstrBadKey') config = {'rFactor escape slash': True} except ValueError: assert False, 'Expected job load to succeed' assert _jobs # Execute # For each job in jobsFile for job in _jobs["jobs"]: _j = ScriptedJsonEditor.Job(_jobs["job definitions"][job], config) # read the file to be edited _j._load( test_test_strings.playerJSONstr, 'test_test_strings.playerJSONstr') # do the edits # if successful: # backup 'filepath' # save new contents to 'filepath try: _j.run_edits() except KeyError: return # failed as expected, try the next job except ValueError: assert False, 'Didn\'t expect ValueError' except BaseException: assert False, 'Didn\'t expect other error' assert False, 'Expected job to fail'
def test_run_job(self): _jsonJob = ScriptedJsonEditor.JsonJobsFile() _jsonJob._load(command_line.JOBS_FILE_HELP_STR, 'command_line.JOBS_FILE_HELP_STR') P_JSON, config = _jsonJob._read() _jsonJobDefs = ScriptedJsonEditor.JsonJobsDefinitionsFile(config) _jsonJobDefs._load(command_line.JOB_DEFINITIONS_FILE_HELP_STR, 'test_test_strings.keyboard_jobs_json_file') _jsonJobDefs._read() """ assert P_JSON["job definitions"]["Letterboxing off"] != None assert P_JSON["job definitions"]["Letterboxing off"]["JSONfileToBeEdited"] != None assert len(P_JSON["job definitions"]["Letterboxing off"]["edits"]) > 0, P_JSON["job definitions"]["Letterboxing off"]["edits"] """ jobs = _jsonJob.get_jobs() assert len(jobs) > 0 """ No longer in the same file assert jobs[0]["JSONfileToBeEdited"] != None assert len(jobs[0]["edits"]) > 0, jobs[0]["edits"] """ for i, job in enumerate(jobs): _j = ScriptedJsonEditor.Job(job, config) # read the file to be edited P_JSON = _j._load(test_test_strings.playerJSONstr, 'test_test_strings.playerJSONstr') assert P_JSON["Graphic Options"] is not None assert P_JSON["Graphic Options"][ "Allow HUD in cockpit"] is not None assert P_JSON["Graphic Options"]["Allow HUD in cockpit"], P_JSON[ "Graphic Options"]["Allow HUD in cockpit"] # before job assert _j._get_value("Graphic Options", "Allow Letterboxing"), _j._get_value( "Graphic Options", "Allow Letterboxing") # do the edits _j.run_edits() if i == 0: assert _j._get_value( "Graphic Options", "Allow Letterboxing") == False, _j._get_value( "Graphic Options", "Allow Letterboxing") else: assert _j._get_value("Graphic Options", "Automap") == 2, _j._get_value( "Graphic Options", "Automap")
def test_main_JSONfileToBeEdited(self): sys.argv = ['ScriptedJsonEditor', 'jobs\\VR.json'] _clo = command_line.CommandLine() jobsFile = _clo.get_jobs_file() if jobsFile: _JSNO_O = ScriptedJsonEditor.JsonJobsFile() __, config = _JSNO_O.read(jobsFile) _jobs = _JSNO_O.get_jobs() if _jobs: # Execute # For each job in jobsFile for job in _jobs: _j = ScriptedJsonEditor.Job(job, config) # read the file to be edited _j._load( test_test_strings.playerJSONstr, 'test_test_strings.playerJSONstr') else: assert False, 'No jobs in jobs\\VR.json' else: assert False, r'No jobsfile jobs\VR.json'