コード例 #1
0
    def test_to_csv(self):
        """ Test stats instance dict to csv conversion """
        with mock.patch('PatternOmatic.ge.stats.time') as mock_time:
            mock_time.return_value = .123
            self.stats.aes = 10
            self.stats.mbf = 0.5
            self.stats.mean_time = 0.22
            self.stats.success_rate = 0.5

            # When a best individual has not been found
            csv_stats = \
                f'{.123}\t{self.stats.mbf}\t{self.stats.success_rate}\t{self.stats.aes}\t{self.stats.mean_time}\t' \
                f'{None}\t'

            super().assertEqual(csv_stats, self.stats._to_csv())

            # When a best individual has been found
            i = object.__new__(Individual)
            i.__setattr__(self.fitness_value_literal, 1.0)
            self.stats.most_fitted_accumulator = [i]

            csv_stats += f'{None}\t{i.fitness_value}\t'
            super().assertEqual(csv_stats, self.stats._to_csv())

            # Also check csv is correctly persisted
            config = Config()
            config.report_path = self.test_report_path_file
            config.report_format = ReportFormat.CSV
            self.stats.persist()

            with open(self.test_report_path_file, 'r') as persisted_report:
                red_report = persisted_report.readlines()

            super().assertEqual(csv_stats + '\n', red_report[0])
コード例 #2
0
    def test_persist(self):
        config = Config()
        config.report_format = ReportFormat.JSON
        config.report_path = self.test_report_path_file

        # When a best individual has been found
        i = object.__new__(Individual)
        i.__setattr__(self.fitness_value_literal, 1.0)
        self.stats.aes = 100
        self.stats.mbf = 0.9
        self.stats.mean_time = 0.42
        self.stats.success_rate = 1.0
        self.stats.most_fitted_accumulator = [i]
        self.stats.persist()

        with open(self.test_report_path_file, 'r') as persisted_report:
            red_report = persisted_report.readlines()

        super().assertEqual(str(dict(self.stats)) + '\n', red_report[0])

        # When a best individual has not been found
        self.stats.most_fitted_accumulator = []
        self.stats.persist()

        with open(self.test_report_path_file, 'r') as persisted_report:
            red_report = persisted_report.readlines()

        super().assertEqual(str(dict(self.stats)) + '\n', red_report[1])
コード例 #3
0
ファイル: test_settings.py プロジェクト: revuel/PatternOmatic
    def test_setting_config_attribute_with_wrong_type_has_no_effect(self):
        config = Config()

        config.max_runs = 0.5
        config.use_extended_pattern_syntax = None
        config.fitness_function_type = RecombinationType.RANDOM_ONE_POINT_CROSSOVER
        config.report_path = 0

        super().assertNotEqual(config.max_runs, 0.5)
        super().assertNotEqual(config.use_extended_pattern_syntax, None)
        super().assertNotEqual(config.fitness_function_type,
                               RecombinationType.RANDOM_ONE_POINT_CROSSOVER)
        super().assertNotEqual(config.report_path, 0)