<commit_before>import pytest
from mock import patch
import re
import subprocess
import uuid

from .. import conf
from ..cli import main
from .directory import directory
from .fakes import fake_getaddrinfo


def test_help(tmpdir, cli):
    with cli(
        args=['ceph-deploy', 'new', '--help'],
        stdout=subprocess.PIPE,
        ) as p:
        result = p.stdout.read()
    assert 'usage: ceph-deploy new' in result
    assert 'positional arguments' in result
    assert 'optional arguments' in result


def test_write_global_conf_section(tmpdir, cli):
    with patch('ceph_deploy.new.socket.gethostbyname'):
        with patch('ceph_deploy.new.socket.getaddrinfo', fake_getaddrinfo):
            with directory(str(tmpdir)):
                main(args=['new', 'host1'])
    with tmpdir.join('ceph.conf').open() as f:
        cfg = conf.parse(f)
    assert cfg.sections() == ['global']


def pytest_funcarg__newcfg(request):
    tmpdir = request.getfuncargvalue('tmpdir')
    cli = request.getfuncargvalue('cli')

    def new(*args):
        with patch('ceph_deploy.new.socket.gethostbyname'):
            with patch('ceph_deploy.new.socket.getaddrinfo', fake_getaddrinfo):
                with directory(str(tmpdir)):
                    main( args=['new'] + list(args))
                    with tmpdir.join('ceph.conf').open() as f:
                        cfg = conf.parse(f)
                    return cfg
    return new


def test_uuid(newcfg):
    cfg = newcfg('host1')
    fsid = cfg.get('global', 'fsid')
    # make sure it's a valid uuid
    uuid.UUID(hex=fsid)
    # make sure it looks pretty, too
    UUID_RE = re.compile(
        r'^[0-9a-f]{8}-'
        + r'[0-9a-f]{4}-'
        # constant 4 here, we want to enforce randomness and not leak
        # MACs or time
        + r'4[0-9a-f]{3}-'<commit_msg>fix conf changes for test_cli_new<commit_after>from mock import patch
import re
import subprocess
import uuid

from .. import conf
from ..cli import main
from .directory import directory
from .fakes import fake_getaddrinfo


def test_help(tmpdir, cli):
    with cli(
        args=['ceph-deploy', 'new', '--help'],
        stdout=subprocess.PIPE,
        ) as p:
        result = p.stdout.read()
    assert 'usage: ceph-deploy new' in result
    assert 'positional arguments' in result
    assert 'optional arguments' in result


def test_write_global_conf_section(tmpdir, cli):
    with patch('ceph_deploy.new.net.get_nonlocal_ip', lambda x: '10.0.0.1'):
        with patch('ceph_deploy.new.arg_validators.Hostname', lambda: lambda x: x):
            with directory(str(tmpdir)):
                main(args=['new', 'host1'])
    with tmpdir.join('ceph.conf').open() as f:
        cfg = conf.ceph.parse(f)
    assert cfg.sections() == ['global']


def pytest_funcarg__newcfg(request):
    tmpdir = request.getfuncargvalue('tmpdir')
    cli = request.getfuncargvalue('cli')

    def new(*args):
        with patch('ceph_deploy.new.net.get_nonlocal_ip', lambda x: '10.0.0.1'):
            with patch('ceph_deploy.new.arg_validators.Hostname', lambda: lambda x: x):
                with directory(str(tmpdir)):
                    main( args=['new'] + list(args))
                    with tmpdir.join('ceph.conf').open() as f:
                        cfg = conf.ceph.parse(f)
                    return cfg
    return new


def test_uuid(newcfg):
    cfg = newcfg('host1')
    fsid = cfg.get('global', 'fsid')
    # make sure it's a valid uuid
    uuid.UUID(hex=fsid)
    # make sure it looks pretty, too
    UUID_RE = re.compile(
        r'^[0-9a-f]{8}-'
        + r'[0-9a-f]{4}-'
        # constant 4 here, we want to enforce randomness and not leak
        # MACs or time
        + r'4[0-9a-f]{3}-'
{'fraction_non_alphanumeric': 0.1301775147928994, 'fraction_numerical': 0.009682625067240451, 'mean_word_length': 2.4789522918615527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4130897', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1205, 'n_words': 301}