<commit_before>import pickle
import os
from os.path import join, expanduser

from spec import eq_, ok_, raises
from mock import patch, call

from invoke.config import Config
from invoke.exceptions import (
    AmbiguousEnvVar, UncastableEnvVar, UnknownFileType
)
from invoke.vendor import six

from _util import IntegrationSpec, skip_if_windows


CONFIGS_PATH = 'configs'
TYPES = ('yaml', 'yml', 'json', 'python')

def _load(kwarg, type_):
    path = join(CONFIGS_PATH, type_ + "/")
    return Config(**{kwarg: path})

class Config_(IntegrationSpec):
    class class_attrs:
        # TODO: move all other non-data-bearing kwargs to this mode
        class prefix:
            def defaults_to_invoke(self):
                eq_(Config().prefix, 'invoke')

            @patch.object(Config, '_load_yaml')
            def informs_config_filenames(self, load_yaml):
                class MyConf(Config):
                    prefix = 'other'
                MyConf(system_prefix='dir/')
                load_yaml.assert_any_call('dir/other.yaml')

            def informs_env_var_prefix(self):
                os.environ['OTHER_FOO'] = 'bar'
                class MyConf(Config):
                    prefix = 'other'
                c = MyConf(defaults={'foo': 'notbar'})
                c.load_shell_env()
                eq_(c.foo, 'bar')

        class file_prefix:
            def defaults_to_None(self):
                eq_(Config().file_prefix, None)

            @patch.object(Config, '_load_yaml')
            def informs_config_filenames(self, load_yaml):
                class MyConf(Config):
                    file_prefix = 'other'
                MyConf(system_prefix='dir/')
                load_yaml.assert_any_call('dir/other.yaml')

        class env_prefix:
            def defaults_to_None(self):
                eq_(Config().env_prefix, None)

            def informs_env_vars_loaded(self):
                os.environ['OTHER_FOO'] = 'bar'
                class MyConf(Config):
                    env_prefix = 'other'
                c = MyConf(defaults={'foo': 'notbar'})
                c.load_shell_env()
                eq_(c.foo, 'bar')

    class global_defaults:
        def basic_settings(self):
            # Just a catchall for what the baseline config settings should
            # be...for some reason we're not actually capturing all of these
            # reliably (even if their defaults are often implied by the tests
            # which override them, e.g. runner tests around warn=True, etc).
            eq_(
                Config.global_defaults(), {
                    'run': {
                        'echo': False,
                        'echo_stdin': None,
                        'encoding': None,
                        'env': {},
                        'err_stream': None,
                        'fallback': True,
                        'hide': None,
                        'in_stream': None,
                        'out_stream': None,
                        'pty': False,
                        'replace_env': False,
                        'shell': '/bin/bash',
                        'warn': False,
                        'watchers': [],
                    },
                    'sudo': {
                        'password': <PASSWORD>,
                        'prompt': '[sudo] password: ',
                        'user': None,
                    },
                    'tasks': {
                        'dedupe': True,
                    },
                },
            )

    class init:
        "__init__"

        def can_be_empty(self):
            eq_(Config().__class__, Config) # derp

        @patch.object(Config, '_load_yaml')
        def configure_global_location_prefix(self, load_yaml):
            # This is a bit funky but more useful than just replicating the
            # same test farther down?
            Config(system_prefix='meh/')
            load_yaml.assert_any_call('meh/invoke.yaml')

        @skip_if_windows
        @patch.object(Config, '_load_yaml')
        def default_system_prefix_is_etc(self, load_yaml):
            # TODO: make this work on Windows somehow without being a total
            # tautology? heh.
            Config()
            load_yaml.assert_any_call('/etc/invoke.yaml')

        @patch.object(Config, '_load_yaml')
        def configure_user_location_prefix(self, load_yaml):
            Config(user_prefix='whatever/')
            load_yaml.assert_any_call('whatever/invoke.yaml')

        @patch.object(Config, '_load_yaml')
        def default_user_prefix_is_homedir_plus_dot(self, load_yaml):
            Config()
            load_yaml.assert_any_call(expanduser('~/.invoke.yaml'))

        @patch.object(Config, '_load_yaml')
        def configure_project_location(self, load_yaml):
            Config(project_home='someproject')
            load_yaml.assert_any_call('someproject/invoke.yaml')

        @patch.object(Config, '_load_yaml')
        def configure_runtime_path(self, load_yaml):
            Config(runtime_path='some/path.yaml')
            load_yaml.assert_any_call('some/path.yaml')

        def accepts_defaults_dict_kwarg(self):
            c = Config(defaults={'super': 'low level'})
            eq_(c.super, 'low level')

        def overrides_dict_is_first_posarg(self):
            c = Config({'new': 'data', 'run': {'hide': True}})
            eq_(c.run.hide, True) # default is False
            eq_(c.run.warn, False) # in global defaults, untouched
            eq_(c.new, 'data') # data only present at overrides layer

        def overrides_dict_is_also_a_kwarg(self):
            c = Config(overrides={'run': {'hide': True}})
            eq_(c.run.hide, True)

        @patch.object(Config, 'post_init')
        def can_defer_post_init_step(self, post_init):<commit_msg>Fix config test compat on windows<commit_after>import pickle
import os
from os.path import join, expanduser

from spec import eq_, ok_, raises
from mock import patch, call

from invoke.config import Config
from invoke.exceptions import (
    AmbiguousEnvVar, UncastableEnvVar, UnknownFileType
)
from invoke.vendor import six

from _util import IntegrationSpec, skip_if_windows


CONFIGS_PATH = 'configs'
TYPES = ('yaml', 'yml', 'json', 'python')

def _load(kwarg, type_):
    path = join(CONFIGS_PATH, type_ + "/")
    return Config(**{kwarg: path})

class Config_(IntegrationSpec):
    class class_attrs:
        # TODO: move all other non-data-bearing kwargs to this mode
        class prefix:
            def defaults_to_invoke(self):
                eq_(Config().prefix, 'invoke')

            @patch.object(Config, '_load_yaml')
            def informs_config_filenames(self, load_yaml):
                class MyConf(Config):
                    prefix = 'other'
                MyConf(system_prefix='dir/')
                load_yaml.assert_any_call('dir/other.yaml')

            def informs_env_var_prefix(self):
                os.environ['OTHER_FOO'] = 'bar'
                class MyConf(Config):
                    prefix = 'other'
                c = MyConf(defaults={'foo': 'notbar'})
                c.load_shell_env()
                eq_(c.foo, 'bar')

        class file_prefix:
            def defaults_to_None(self):
                eq_(Config().file_prefix, None)

            @patch.object(Config, '_load_yaml')
            def informs_config_filenames(self, load_yaml):
                class MyConf(Config):
                    file_prefix = 'other'
                MyConf(system_prefix='dir/')
                load_yaml.assert_any_call('dir/other.yaml')

        class env_prefix:
            def defaults_to_None(self):
                eq_(Config().env_prefix, None)

            def informs_env_vars_loaded(self):
                os.environ['OTHER_FOO'] = 'bar'
                class MyConf(Config):
                    env_prefix = 'other'
                c = MyConf(defaults={'foo': 'notbar'})
                c.load_shell_env()
                eq_(c.foo, 'bar')

    class global_defaults:
        def basic_settings(self):
            # Just a catchall for what the baseline config settings should
            # be...for some reason we're not actually capturing all of these
            # reliably (even if their defaults are often implied by the tests
            # which override them, e.g. runner tests around warn=True, etc).
            eq_(
                Config.global_defaults(), {
                    'run': {
                        'echo': False,
                        'echo_stdin': None,
                        'encoding': None,
                        'env': {},
                        'err_stream': None,
                        'fallback': True,
                        'hide': None,
                        'in_stream': None,
                        'out_stream': None,
                        'pty': False,
                        'replace_env': False,
                        'shell': '/bin/bash',
                        'warn': False,
                        'watchers': [],
                    },
                    'sudo': {
                        'password': None,
                        'prompt': '[sudo] password: ',
                        'user': None,
                    },
                    'tasks': {
                        'dedupe': True,
                    },
                },
            )

    class init:
        "__init__"

        def can_be_empty(self):
            eq_(Config().__class__, Config) # derp

        @patch.object(Config, '_load_yaml')
        def configure_global_location_prefix(self, load_yaml):
            # This is a bit funky but more useful than just replicating the
            # same test farther down?
            Config(system_prefix='meh/')
            load_yaml.assert_any_call('meh/invoke.yaml')

        @skip_if_windows
        @patch.object(Config, '_load_yaml')
        def default_system_prefix_is_etc(self, load_yaml):
            # TODO: make this work on Windows somehow without being a total
            # tautology? heh.
            Config()
            load_yaml.assert_any_call('/etc/invoke.yaml')

        @patch.object(Config, '_load_yaml')
        def configure_user_location_prefix(self, load_yaml):
            Config(user_prefix='whatever/')
            load_yaml.assert_any_call('whatever/invoke.yaml')

        @patch.object(Config, '_load_yaml')
        def default_user_prefix_is_homedir_plus_dot(self, load_yaml):
            Config()
            load_yaml.assert_any_call(expanduser('~/.invoke.yaml'))

        @patch.object(Config, '_load_yaml')
        def configure_project_location(self, load_yaml):
            Config(project_home='someproject')
            load_yaml.assert_any_call(join('someproject', 'invoke.yaml'))

        @patch.object(Config, '_load_yaml')
        def configure_runtime_path(self, load_yaml):
            Config(runtime_path='some/path.yaml')
            load_yaml.assert_any_call('some/path.yaml')

        def accepts_defaults_dict_kwarg(self):
            c = Config(defaults={'super': 'low level'})
            eq_(c.super, 'low level')

        def overrides_dict_is_first_posarg(self):
            c = Config({'new': 'data', 'run': {'hide': True}})
            eq_(c.run.hide, True) # default is False
            eq_(c.run.warn, False) # in global defaults, untouched
            eq_(c.new, 'data') # data only present at overrides layer

        def overrides_dict_is_also_a_kwarg(self):
            c = Config(overrides={'run': {'hide': True}})
            eq_(c.run.hide, True)

        @patch.object(Config, 'post_init')
        def can_defer_post_init_step(self, post_init):
{'fraction_non_alphanumeric': 0.106020381947418, 'fraction_numerical': 0.0, 'mean_word_length': 1.6932656826568266, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '6563471', 'n_tokens_mistral': 3271, 'n_tokens_neox': 3102, 'n_words': 703}