<commit_before>"""Tests for Bower Installer."""

import unittest
from grow.common import base_config
from grow.pods import pods
from grow.pods import storage
from grow.sdk.installers import bower_installer
from grow.testing import testing


class BowerInstallerTestCase(unittest.TestCase):
    """Test the Bower Installer."""

    def setUp(self):
        self.config = base_config.BaseConfig()
        self.dir_path = testing.create_test_pod_dir()
        self.pod = pods.Pod(self.dir_path, storage=storage.FileStorage)
        self.installer = bower_installer.BowerInstaller(
            self.pod, self.config)

    def test_should_run(self):
        """Test if installer should run."""
        self.assertFalse(self.installer.should_run)
        self.pod.write_file('bower.json', '')
        self.assertTrue(self.installer.should_run)<commit_msg>Adding more tests for the bower installer.<commit_after>"""Tests for Bower Installer."""

import unittest
import mock
from grow.common import base_config
from grow.pods import pods
from grow.pods import storage
from grow.sdk.installers import base_installer
from grow.sdk.installers import bower_installer
from grow.testing import testing


class BowerInstallerTestCase(unittest.TestCase):
    """Test the Bower Installer."""

    def setUp(self):
        self.config = base_config.BaseConfig()
        self.dir_path = testing.create_test_pod_dir()
        self.pod = pods.Pod(self.dir_path, storage=storage.FileStorage)
        self.installer = bower_installer.BowerInstaller(
            self.pod, self.config)

    @mock.patch('subprocess.call')
    def test_check_prerequisites(self, mock_call):
        """Test if install runs the correct processes."""
        mock_call.return_value = 0
        self.installer.check_prerequisites()
        mock_call.assert_called_once_with(
            'bower --version > /dev/null 2>&1', **self.installer.subprocess_args(shell=True))

    @mock.patch('subprocess.call')
    def test_check_prerequisites_fail(self, mock_call):
        """Test if install runs the correct processes."""
        mock_call.return_value = 127
        with self.assertRaises(base_installer.MissingPrerequisiteError):
            self.installer.check_prerequisites()

    @mock.patch('subprocess.Popen')
    def test_install(self, mock_popen):
        """Test if install runs the correct processes."""
        mock_process = mock.Mock()
        mock_process.wait.return_value = 0
        mock_popen.return_value = mock_process
        self.installer.install()
        mock_popen.assert_called_once_with(
            'bower install', **self.installer.subprocess_args(shell=True))

    @mock.patch('subprocess.Popen')
    def test_install_failed(self, mock_popen):
        """Test if install runs the correct processes."""
        mock_process = mock.Mock()
        mock_process.wait.return_value = 1
        mock_popen.return_value = mock_process
        with self.assertRaises(base_installer.InstallError):
            self.installer.install()

    def test_should_run(self):
        """Test if installer should run."""
        self.assertFalse(self.installer.should_run)
        self.pod.write_file('bower.json', '')
        self.assertTrue(self.installer.should_run)
{'fraction_non_alphanumeric': 0.10204081632653061, 'fraction_numerical': 0.0024737167594310453, 'mean_word_length': 3.3657219973009447, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6976249', 'n_tokens_mistral': 969, 'n_tokens_neox': 939, 'n_words': 199}