<commit_before>from mock import Mock, patch
from sprinter.testtools import FormulaTest
from sprinter import lib


source_config = """
[no_update]
formula = sprinter.formula.package
apt-get = gitA

[update_new_package]
formula = sprinter.formula.package
apt-get = gitA
"""

target_config = """
[simple_example]
formula = sprinter.formula.package
brew = git
apt-get = git-core
yum = git-core

[no_update]
formula = sprinter.formula.package
apt-get = gitA

[update_new_package]
formula = sprinter.formula.package
apt-get = gitB
"""


class TestPackageFormula(FormulaTest):

    def setup(self):
        super(TestPackageFormula, self).setup(source_config=source_config,
                                              target_config=target_config)
        self.environment.system.isDebianBased = Mock(return_value=False)
        self.environment.system.isOSX = Mock(return_value=False)
        self.environment.system.isFedoraBased = Mock(return_value=False)
        self.which_original = lib.which
        lib.which = Mock(return_value=True)

    def teardown(self):
        lib.which = self.which_original

    @patch.object(lib, 'call')
    def test_simple_example_osx(self, call):
        """ A brew package should install on osx """
        self.environment.system.isOSX = Mock(return_value=True)
        self.environment.run_feature('simple_example', 'sync')
        call.assert_called_with("brew install git")

    @patch.object(lib, 'call')
    def test_simple_example_debian(self, call):
        """ An apt-get package should install on debian """
        self.environment.system.isDebianBased = Mock(return_value=True)
        self.environment.run_feature('simple_example', 'sync')
        call.assert_called_with("sudo apt-get -y install git-core")

    @patch.object(lib, 'call')
    def test_simple_example_fedora(self, call):
        """ A yum package should install properly on fedora """
        self.environment.system.isFedoraBased = Mock(return_value=True)
        self.environment.run_feature('simple_example', 'sync')
        call.assert_called_with("sudo yum install git-core")

    @patch.object(lib, 'call')
    def test_no_update(self, call):
        """ An unchanged formula should not be updated """
        self.environment.run_feature('no_update', 'sync')
        assert not call.called, "Update was called!"

    @patch.object(lib, 'call')
    def test_update_different_package(self, call):
        """ An feature with a new formula """
        self.environment.system.isDebianBased = Mock(return_value=True)
        self.environment.run_feature('update_new_package', 'sync')
        call.assert_called_with("sudo apt-get -y install gitB")<commit_msg>Fixing tests<commit_after>import logging
from mock import Mock, patch
from sprinter.testtools import FormulaTest
from sprinter import lib


source_config = """
[no_update]
formula = sprinter.formula.package
apt-get = gitA

[update_new_package]
formula = sprinter.formula.package
apt-get = gitA
"""

target_config = """
[simple_example]
formula = sprinter.formula.package
brew = git
apt-get = git-core
yum = git-core

[no_update]
formula = sprinter.formula.package
apt-get = gitA

[update_new_package]
formula = sprinter.formula.package
apt-get = gitB
"""


class TestPackageFormula(FormulaTest):

    def setup(self):
        super(TestPackageFormula, self).setup(source_config=source_config,
                                              target_config=target_config)
        self.environment.system.isDebianBased = Mock(return_value=False)
        self.environment.system.isOSX = Mock(return_value=False)
        self.environment.system.isFedoraBased = Mock(return_value=False)
        self.which_original = lib.which
        lib.which = Mock(return_value=True)

    def teardown(self):
        lib.which = self.which_original

    @patch.object(lib, 'call')
    def test_simple_example_osx(self, call):
        """ A brew package should install on osx """
        self.environment.system.isOSX = Mock(return_value=True)
        self.environment.run_feature('simple_example', 'sync')
        call.assert_called_with("brew install git", output_log_level=logging.DEBUG, stdout=None)

    @patch.object(lib, 'call')
    def test_simple_example_debian(self, call):
        """ An apt-get package should install on debian """
        self.environment.system.isDebianBased = Mock(return_value=True)
        self.environment.run_feature('simple_example', 'sync')
        call.assert_called_with("sudo apt-get -y install git-core", output_log_level=logging.DEBUG, stdout=None)

    @patch.object(lib, 'call')
    def test_simple_example_fedora(self, call):
        """ A yum package should install properly on fedora """
        self.environment.system.isFedoraBased = Mock(return_value=True)
        self.environment.run_feature('simple_example', 'sync')
        call.assert_called_with("sudo yum install git-core", output_log_level=logging.DEBUG, stdout=None)

    @patch.object(lib, 'call')
    def test_no_update(self, call):
        """ An unchanged formula should not be updated """
        self.environment.run_feature('no_update', 'sync')
        assert not call.called, "Update was called!"

    @patch.object(lib, 'call')
    def test_update_different_package(self, call):
        """ An feature with a new formula """
        self.environment.system.isDebianBased = Mock(return_value=True)
        self.environment.run_feature('update_new_package', 'sync')
        call.assert_called_with("sudo apt-get -y install gitB", output_log_level=logging.DEBUG, stdout=None)
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.0, 'mean_word_length': 3.620833333333333, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5916647', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1633, 'n_words': 342}