def test_score_eco_user_package_dict(self):
        """Test the dependency dict deserialization, frequency list deserialization etc."""
        input_data_store = LocalFileSystem(
            "tests/data/data_pgm/input-score-data/")
        self.assertIsNotNone(input_data_store)

        output_data_store = LocalFileSystem(
            "tests/data/data_pgm/output-score-data/")
        self.assertIsNotNone(output_data_store)

        frequency_dict_data_store = LocalFileSystem(
            src_dir="tests/data/data_apollo/")
        self.assertIsNotNone(frequency_dict_data_store)

        user_eco_kronos_dict = load_user_eco_to_kronos_model_dict(
            input_kronos_data_store=input_data_store, additional_path="")

        self.assertIsNotNone(user_eco_kronos_dict)

        eco_to_kronos_dependency_dict = get_eco_to_kronos_dependency_dict(
            data_store=input_data_store, folderpath="data_kronos_dependency")

        self.assertIsNotNone(eco_to_kronos_dependency_dict)

        user_request = [{
            "ecosystem": "pypi",
            "comp_package_count_threshold": 10,
            "alt_package_count_threshold": 1,
            "outlier_probability_threshold": 0.61,
            "unknown_packages_ratio_threshold": 0.4,
            "outlier_package_count_threshold": 2,
            "package_list": ["p1", "p2", "p3", "np1"]
        }]

        frequency_dict = frequency_dict_data_store.read_json_file(
            filename=KD_PACKAGE_FREQUENCY)
        self.assertIsNotNone(frequency_dict)
        all_package_list_obj = RecommendationValidator.load_package_list_local(
            input_folder_name="tests/data/data_recom_valid/",
            additional_path="")

        response = score_eco_user_package_dict(
            user_request,
            user_eco_kronos_dict=user_eco_kronos_dict,
            eco_to_kronos_dependency_dict=eco_to_kronos_dependency_dict,
            all_package_list_obj=all_package_list_obj,
            package_frequency_dict=frequency_dict,
            use_filters=USE_FILTERS)

        self.assertIsNotNone(response)

        output_data_store.write_json_file(filename="response.json",
                                          contents=response)

        expected_response = output_data_store.read_json_file(
            filename="expected_response.json")
        self.assertIsNotNone(expected_response)

        self.assertDictEqual(response[0], expected_response[0])
Esempio n. 2
0
        def test_score_eco_user_package_dict(self):
            input_data_store = LocalFileSystem(
                "tests/data/data_pgm/input-score-data/")
            self.assertTrue(input_data_store is not None)

            output_data_store = LocalFileSystem(
                "tests/data/data_pgm/output-score-data/")
            self.assertTrue(output_data_store is not None)

            user_eco_kronos_dict = load_user_eco_to_kronos_model_dict(
                input_kronos_data_store=input_data_store, additional_path="")

            self.assertTrue(user_eco_kronos_dict is not None)

            eco_to_kronos_dependency_dict = get_eco_to_kronos_dependency_dict(
                data_store=input_data_store,
                folderpath="data_kronos_dependency")

            self.assertTrue(eco_to_kronos_dependency_dict is not None)

            user_request = [{
                "ecosystem":
                "pypi",
                "comp_package_count_threshold":
                10,
                "alt_package_count_threshold":
                1,
                "outlier_probability_threshold":
                0.61,
                "unknown_packages_ratio_threshold":
                0.4,
                "outlier_package_count_threshold":
                2,
                "package_list": ["p1", "p2", "p3", "np1", "p2", "p3", "p1"]
            }]

            response = score_eco_user_package_dict(
                user_request,
                user_eco_kronos_dict=user_eco_kronos_dict,
                eco_to_kronos_dependency_dict=eco_to_kronos_dependency_dict,
                all_package_list_obj=None)

            self.assertTrue(response is not None)

            output_data_store.write_json_file(filename="response.json",
                                              contents=response)

            expected_response = output_data_store.read_json_file(
                filename="expected_response.json")
            self.assertTrue(expected_response is not None)

            self.assertDictEqual(response[0], expected_response[0])