def test_collect_and_add_individual_metrics_to_json_no_overwrite(tmp_path): """Check that calculated data was collected from the repository and was written.""" read_test_file = "individual_metrics_testfile" d = tmp_path / "sub" d.mkdir() p1 = d / "calculated_metrics_testfile.json" entry = '"Keep this file empty" : []' p1.write_text("{" + entry + "}") # retreive the dictionaries from the test file calculated_data_from_file = json_handler.get_dict_from_json_file( "calculated_metrics_testfile", d) raw_data_from_file = json_handler.get_dict_from_json_file(read_test_file) # Makes sure that the default values are in the dicitionaries # The key is called "Keep this file empty" assert "Keep this file empty" in calculated_data_from_file # makes sure RAW_DATA is a key in the individual_metrics_testfile assert "RAW_DATA" in raw_data_from_file # Call collect and write funciton data_collection.collect_and_add_individual_metrics_to_json( read_test_file, "calculated_metrics_testfile", d, overwrite=False) # Update dicitionary from the new data in the file calculated_data_from_file = json_handler.get_dict_from_json_file( "calculated_metrics_testfile", d) # Make sure the correct keys are added expected_keys = [ "Keep this file empty", "schultzh", "WonjoonC", "Jordan-A", "noorbuchi", "Chris Stephenson", ] actual_keys = list(calculated_data_from_file.keys()) assert actual_keys == expected_keys
def test_get_dict_from_json(json_file, expected_contents): """Ensure data is correctly pulled from a json file.""" assert json_file + ".json" in os.listdir("./data/") # demofile exists test_dictionary = json_handler.get_dict_from_json_file(json_file) for user in expected_contents: assert user in test_dictionary.keys()
def test_get_dict_from_json(json_name, expected_contents): """Ensure data is correctly pulled from a json file.""" if ".json" in json_name: assert json_name in os.listdir("./data/") # file is created assert json_name + ".json" not in os.listdir("./data/") # Input handling created correct file else: assert json_name + ".json" in os.listdir("./data/") # file is created assert json_name + ".json.json" not in os.listdir("./data/") # file to test exists test_dictionary = json_handler.get_dict_from_json_file(json_name) for user in expected_contents: assert user in test_dictionary.keys()
def test_collect_and_add_raw_data_to_json_no_overwrite(tmp_path): """Check that raw data was collected from the repository and was written.""" d = tmp_path / "sub" d.mkdir() p1 = d / "raw_data_testfile_no_overwrite.json" entry = '"Keep this file empty" : []' p1.write_text("{" + entry + "}") # retreive the dictionary from the test file data_from_file = json_handler.get_dict_from_json_file( "raw_data_testfile_no_overwrite", d) # Makes sure that the default key is in the dicitionary # The key is called "Keep this file empty" assert "Keep this file empty" in data_from_file repository = "https://github.com/GatorCogitate/cogitate_tool" # Call collect and write funciton data_collection.collect_and_add_raw_data_to_json( repository, "raw_data_testfile_no_overwrite", d, overwrite=False) # Update dicitionary from the new data in the file data_from_file = json_handler.get_dict_from_json_file( "raw_data_testfile_no_overwrite", d) # Make sure the correct key is added assert "RAW_DATA" in data_from_file assert "Keep this file empty" in data_from_file
repository = data_collection.authenticate_repository(input_token, repository_name) if repository == "INVALID": pytest.skip("Rate Limit Exceeded.") assert repository is not None @pytest.mark.parametrize( "input_token,repository_name,state,contributor_data", [ ( data_collection.retrieve_token("data/token.txt"), "GatorCogitate/cogitate_tool", "all", json_handler.get_dict_from_json_file("contributor_data_template"), ) ], ) def test_retrieve_issue_data_retrieves_issues( # pylint: disable=bad-continuation input_token, repository_name, state, contributor_data, ): """Test to ensure all issues are associated with the correct contributor.""" try: ghub = Github(input_token) repository = ghub.get_repo(repository_name)
def test_raw_data_exists_in_testfile(): """Checks the existence of the key RAW_DATA in individual_metrics_testfile.""" test_dict = json_handler.get_dict_from_json_file( "individual_metrics_testfile") assert "RAW_DATA" in test_dict.keys()