示例#1
0
 def test_existing_config_file_different_parameters(self):
     """
     on a user defined msui_settings_json without a defined num_labels this test should return its default value
     """
     create_msui_settings_file('{"num_interpolation_points": 20 }')
     if not fs.open_fs(MSUI_CONFIG_PATH).exists("msui_settings.json"):
         pytest.skip('undefined test msui_settings.json')
     with fs.open_fs(MSUI_CONFIG_PATH) as file_dir:
         file_content = file_dir.readtext("msui_settings.json")
     assert "num_labels" not in file_content
     default_data = config_loader(default=True)
     config_file = fs.path.combine(MSUI_CONFIG_PATH, "msui_settings.json")
     read_config_file(path=config_file)
     data = config_loader()
     assert data["num_labels"] == default_data["num_labels"]
     num_labels = config_loader(dataset="num_labels")
     assert num_labels == default_data["num_labels"]
     num_interpolation_points = config_loader(
         dataset="num_interpolation_points")
     assert num_interpolation_points == 20
     assert data["num_interpolation_points"] == 20
     with pytest.raises(KeyError):
         config_loader(dataset="UNDEFINED")
     with pytest.raises(KeyError):
         assert config_loader(dataset="UNDEFINED")
示例#2
0
 def test_modify_config_file_with_invalid_parameters(self):
     """
     Test to check if modify_config_file raises a KeyError when a key is empty
     """
     create_msui_settings_file('{ }')
     if not fs.open_fs(MSUI_CONFIG_PATH).exists("msui_settings.json"):
         pytest.skip('undefined test msui_settings.json')
     data_to_save_in_config_file = {
         "": "sree",
         "MSCOLAB_mailid": "*****@*****.**"
     }
     with pytest.raises(KeyError):
         modify_config_file(data_to_save_in_config_file)
示例#3
0
 def test_modify_config_file_with_existing_parameters(self):
     """
     Test to check if modify_config_file properly modifies a key-value pair in the config file
     """
     create_msui_settings_file('{"MSCOLAB_mailid": "*****@*****.**"}')
     if not fs.open_fs(MSUI_CONFIG_PATH).exists("msui_settings.json"):
         pytest.skip('undefined test msui_settings.json')
     data_to_save_in_config_file = {"MSCOLAB_mailid": "*****@*****.**"}
     modify_config_file(data_to_save_in_config_file)
     config_file = fs.path.combine(MSUI_CONFIG_PATH, "msui_settings.json")
     read_config_file(path=config_file)
     data = config_loader()
     assert data["MSCOLAB_mailid"] == "*****@*****.**"
示例#4
0
 def test_add_users_with_updating_credentials_in_config_file(
         self, mockmessage):
     create_msui_settings_file(
         '{"MSCOLAB_mailid": "*****@*****.**", "MSCOLAB_password": "******"}'
     )
     read_config_file()
     # check current settings
     assert config_loader(
         dataset="MSCOLAB_mailid") == "*****@*****.**"
     assert config_loader(dataset="MSCOLAB_password") == "something"
     self._connect_to_mscolab()
     assert self.window.mscolab_server_url is not None
     self._create_user("anand", "*****@*****.**", "anand")
     # check changed settings
     assert config_loader(dataset="MSCOLAB_mailid") == "*****@*****.**"
     assert config_loader(dataset="MSCOLAB_password") == "anand"
     # check user is logged in
     assert self.main_window.usernameLabel.text() == "anand"
示例#5
0
 def test_existing_empty_config_file(self):
     """
     on a user defined empty msui_settings_json this test should return the default value for num_labels
     """
     create_msui_settings_file('{ }')
     if not fs.open_fs(MSUI_CONFIG_PATH).exists("msui_settings.json"):
         pytest.skip('undefined test msui_settings.json')
     with fs.open_fs(MSUI_CONFIG_PATH) as file_dir:
         file_content = file_dir.readtext("msui_settings.json")
     assert ":" not in file_content
     default_data = config_loader(default=True)
     config_file = fs.path.combine(MSUI_CONFIG_PATH, "msui_settings.json")
     read_config_file(path=config_file)
     data = config_loader()
     assert data["num_labels"] == default_data["num_labels"]
     num_labels = config_loader(dataset="num_labels")
     assert num_labels == default_data["num_labels"]
     with pytest.raises(KeyError):
         config_loader(dataset="UNDEFINED")
     with pytest.raises(KeyError):
         assert config_loader(dataset="UNDEFINED")
示例#6
0
    def test_existing_config_file_invalid_parameters(self):
        """
        on a user defined msui_settings_json with duplicate and empty keys should raise FatalUserError
        """
        create_msui_settings_file(
            '{"num_interpolation_points": 201, "num_interpolation_points": 10 }'
        )
        if not fs.open_fs(MSUI_CONFIG_PATH).exists("msui_settings.json"):
            pytest.skip('undefined test msui_settings.json')
        with fs.open_fs(MSUI_CONFIG_PATH) as file_dir:
            file_content = file_dir.readtext("msui_settings.json")
        assert "num_interpolation_points" in file_content
        config_file = fs.path.combine(MSUI_CONFIG_PATH, "msui_settings.json")
        with pytest.raises(utils.FatalUserError):
            read_config_file(path=config_file)

        create_msui_settings_file('{"": 201, "num_labels": 10 }')
        if not fs.open_fs(MSUI_CONFIG_PATH).exists("msui_settings.json"):
            pytest.skip('undefined test msui_settings.json')
        with fs.open_fs(MSUI_CONFIG_PATH) as file_dir:
            file_content = file_dir.readtext("msui_settings.json")
        assert "num_labels" in file_content
        with pytest.raises(utils.FatalUserError):
            read_config_file(path=config_file)
示例#7
0
 def _reset_config_file(self):
     create_msui_settings_file('{ }')
     config_file = fs.path.combine(MSUI_CONFIG_PATH, "msui_settings.json")
     read_config_file(path=config_file)