Exemple #1
0
        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)
Exemple #2
0
    def test_editJson(self):
        if os.path.exists(filepath):
            _JSNO_O = ScriptedJsonEditor.JsonRfactorFile()
            _JSNO_O.read(filepath)
            ##################################
            # change values as required
            ##################################
            for key, item, newValue in test_test_strings.edits:
                try:
                    _JSNO_O.edit(key, item, newValue)
                except KeyError:  # we're expecting one error
                    assert key == 'GraphicOptions', key

            _filepath = filepath + '.edited'
            _JSNO_O.write(_filepath)
    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
Exemple #4
0
 def test_readJsonFile(self):
     if os.path.exists(filepath):
         _JSNO_O = ScriptedJsonEditor.JsonRfactorFile()
         _JSNO_O.read(filepath)
         _filepath = filepath + '.mostlySame'
         _JSNO_O.write(_filepath)
Exemple #5
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