<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_ruleset.py
----------------------------------

Tests for `Ruleset` module.
"""

import unittest

from smartfilesorter.ruleset import RuleSet
from smartfilesorter.matchrules.filenamestartswith import FilenameStartsWith
from smartfilesorter.matchrules.fileextensionis import FileExtensionIs
from smartfilesorter.actionrules.stopprocessing import StopProcessing


class TestRuleSet(unittest.TestCase):
    def setUp(self):
        # Create mock objects for the plugins
        match_plugins = {'filename-starts-with': FilenameStartsWith, 'file-extension-is': FileExtensionIs}
        action_plugins = {'stop-processing': StopProcessing}
        # Represents a single section of the YAML config file
        test_yaml = {'action': 'stop-processing',
                     'match': {'filename-starts-with': 'a', 'file-extension-is': '.jpg .gif .png .jpeg'},
                     'name': 'Just a test'}
        self.ruleset = RuleSet(test_yaml, match_plugins=match_plugins, action_plugins=action_plugins)

    def test_ruleset_name_is_set(self):
        # Name should be set by constructor
        self.assertEqual(str(self.ruleset), 'Ruleset: Just a test')
        self.assertEqual(self.ruleset.name, 'Just a test')

    def test_plugins_available(self):
        # Plugins
        self.assertGreaterEqual(len(self.ruleset.available_match_plugins), 1)
        self.assertGreaterEqual(len(self.ruleset.available_action_plugins), 1)

    def test_add_match_rule(self):
        self.ruleset.add_match_rule(config_name='filename-starts-with', value='abcdef')
        self.assertGreaterEqual(len(self.ruleset.match_rules), 1)

    def test_add_action_rule_without_value(self):
        self.ruleset.add_action_rule(config_name='stop-processing')
        self.assertGreaterEqual(len(self.ruleset.action_rules), 1)

    def test_add_action_rule_with_value(self):
        self.ruleset.add_action_rule(config_name='stop-processing', value='not needed for this rule')
        self.assertGreaterEqual(len(self.ruleset.action_rules), 1)

    def test_add_nonexistent_rule(self):
        # Test that an error is raised when a rule can't be found
        self.assertRaises(IndexError, self.ruleset.add_action_rule, 'i-do-not-exist')

<commit_msg>Updated tests for new ruleset<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_ruleset.py
----------------------------------

Tests for `Ruleset` module.
"""

import unittest

from smartfilesorter.ruleset import RuleSet
from smartfilesorter.matchrules.filenamestartswith import FilenameStartsWith
from smartfilesorter.matchrules.fileextensionis import FileExtensionIs
from smartfilesorter.actionrules.stopprocessing import StopProcessing


class TestRuleSet(unittest.TestCase):
    def setUp(self):
        # Create mock objects for the plugins
        match_plugins = {'filename-starts-with': FilenameStartsWith, 'file-extension-is': FileExtensionIs}
        action_plugins = {'stop-processing': StopProcessing}
        # Represents a single section of the YAML config file
        test_yaml = {'action': 'stop-processing',
                     'match': {'filename-starts-with': 'a', 'file-extension-is': '.jpg .gif .png .jpeg'},
                     'name': 'Just a test'}
        self.ruleset = RuleSet(test_yaml, match_plugins=match_plugins, action_plugins=action_plugins)

    def test_ruleset_name_is_set(self):
        # Name should be set by constructor
        self.assertEqual(str(self.ruleset), 'Ruleset: Just a test')
        self.assertEqual(self.ruleset.name, 'Just a test')

    def test_plugins_available(self):
        # Plugins
        self.assertGreaterEqual(len(self.ruleset.available_match_plugins), 1)
        self.assertGreaterEqual(len(self.ruleset.available_action_plugins), 1)

    def test_add_match_rule(self):
        self.ruleset.add_match_rule({'filename-starts-with': 'abcdef'})
        self.assertGreaterEqual(len(self.ruleset.match_rules), 1)

    def test_add_action_rule_without_value(self):
        self.ruleset.add_action_rule('stop-processing')
        self.assertGreaterEqual(len(self.ruleset.action_rules), 1)

    def test_add_action_rule_with_value(self):
        self.ruleset.add_action_rule({'stop-processing': 'not needed for this rule'})
        self.assertGreaterEqual(len(self.ruleset.action_rules), 1)

    def test_add_nonexistent_rule(self):
        # Test that an error is raised when a rule can't be found
        self.assertRaises(IndexError, self.ruleset.add_action_rule, 'i-do-not-exist')


{'fraction_non_alphanumeric': 0.1185883384480491, 'fraction_numerical': 0.00263042525208242, 'mean_word_length': 3.5767301905717153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5410424', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1352, 'n_words': 274}