<commit_before>from argparse import Namespace
from contextlib import contextmanager

from mock import patch

from assess_bootstrap import (
    assess_bootstrap,
    parse_args,
    )
from jujupy import (
    _temp_env as temp_env,
    )
from tests import (
    FakeHomeTestCase,
    TestCase,
)


class TestParseArgs(TestCase):

    def test_parse_args(self):
        args = parse_args(['foo', 'bar'])
        self.assertEqual(args, Namespace(
            juju='foo', env='bar', debug=False, region=None,
            temp_env_name=None))

    def test_parse_args_debug(self):
        args = parse_args(['foo', 'bar', '--debug'])
        self.assertEqual(args.debug, True)

    def test_parse_args_region(self):
        args = parse_args(['foo', 'bar', '--region', 'foo'])
        self.assertEqual(args.region, 'foo')

    def test_parse_args_temp_env_name(self):
        args = parse_args(['foo', 'bar', 'foo'])
        self.assertEqual(args.temp_env_name, 'foo')


class TestAssessBootstrap(FakeHomeTestCase):

    @contextmanager
    def assess_boostrap_cxt(self):
        call_cxt = patch('subprocess.call')
        cc_cxt = patch('subprocess.check_call')
        co_cxt = patch('subprocess.check_output', return_value='1.25.5')
        env_cxt = temp_env({'environments': {'bar': {'type': 'foo'}}})
        with call_cxt, cc_cxt, co_cxt, env_cxt:
            yield

    def test_assess_bootstrap_defaults(self):
        def check(myself):
            self.assertEqual(myself.env.config,
                             {'name': 'bar', 'type': 'foo'})
        with self.assess_boostrap_cxt():
            with patch('jujupy.EnvJujuClient.bootstrap', side_effect=check,
                       autospec=True):
                assess_bootstrap('/foo', 'bar', False, None, None)
        self.assertRegexpMatches(
            self.log_stream.getvalue(),
            r"(?m)^INFO Environment successfully bootstrapped.$")

    def test_assess_bootstrap_region_temp_env(self):
        def check(myself):<commit_msg>Avoid asserting on jujupy specifics in test_assess_bootstrap<commit_after>from argparse import Namespace
from contextlib import contextmanager

from mock import patch

from assess_bootstrap import (
    assess_bootstrap,
    parse_args,
    )
from jujupy import (
    _temp_env as temp_env,
    )
from tests import (
    FakeHomeTestCase,
    TestCase,
)


class TestParseArgs(TestCase):

    def test_parse_args(self):
        args = parse_args(['foo', 'bar'])
        self.assertEqual(args, Namespace(
            juju='foo', env='bar', debug=False, region=None,
            temp_env_name=None))

    def test_parse_args_debug(self):
        args = parse_args(['foo', 'bar', '--debug'])
        self.assertEqual(args.debug, True)

    def test_parse_args_region(self):
        args = parse_args(['foo', 'bar', '--region', 'foo'])
        self.assertEqual(args.region, 'foo')

    def test_parse_args_temp_env_name(self):
        args = parse_args(['foo', 'bar', 'foo'])
        self.assertEqual(args.temp_env_name, 'foo')


class TestAssessBootstrap(FakeHomeTestCase):

    @contextmanager
    def assess_boostrap_cxt(self):
        call_cxt = patch('subprocess.call')
        cc_cxt = patch('subprocess.check_call')
        gv_cxt = patch('jujupy.EnvJujuClient.get_version',
                       side_effect=lambda cls: '1.25.5')
        gjo_cxt = patch('jujupy.EnvJujuClient.get_juju_output', autospec=True,
                        return_value='')
        env_cxt = temp_env({'environments': {'bar': {'type': 'foo'}}})
        with call_cxt, cc_cxt, gv_cxt, gjo_cxt, env_cxt:
            yield

    def test_assess_bootstrap_defaults(self):
        def check(myself):
            self.assertEqual(myself.env.config,
                             {'name': 'bar', 'type': 'foo'})
        with self.assess_boostrap_cxt():
            with patch('jujupy.EnvJujuClient.bootstrap', side_effect=check,
                       autospec=True):
                assess_bootstrap('/foo', 'bar', False, None, None)
        self.assertRegexpMatches(
            self.log_stream.getvalue(),
            r"(?m)^INFO Environment successfully bootstrapped.$")

    def test_assess_bootstrap_region_temp_env(self):
        def check(myself):
{'fraction_non_alphanumeric': 0.12231404958677686, 'fraction_numerical': 0.0018890200708382527, 'mean_word_length': 2.799103139013453, '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': '3805975', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1307, 'n_words': 252}