<commit_before>"""
Make sure that the old syntax where Server32 required a `quiet` argument is still valid.
"""
import os
import subprocess

try:
    import pytest
except ImportError:  # the 32-bit server does not need pytest installed
    class Mark(object):
        @staticmethod
        def skipif(condition, reason=None):
            def func(function):
                return function
            return func

    class pytest(object):
        mark = Mark

from msl.loadlib import Server32, Client64, SERVER_FILENAME, IS_MAC
from msl.examples.loadlib import EXAMPLES_DIR


class Quiet32(Server32):

    def __init__(self, host, port, quiet, **kwargs):
        super(Quiet32, self).__init__(
            os.path.join(kwargs['ex_dir'], 'cpp_lib32'),
            'cdll', host, port, quiet
        )
        self._kwargs = kwargs

    def add(self, a, b):
        return self.lib.add(a, b)

    def kwargs(self):
        return self._kwargs


class Quiet64(Client64):

    def __init__(self, **kwargs):
        super(Quiet64, self).__init__(__file__, **kwargs)

    def add(self, a, b):
        # a and b must be integers
        return self.request32('add', a, b)

    def kwargs(self):
        return self.request32('kwargs')


@pytest.mark.skipif(IS_MAC, reason='the 32-bit server for macOS does not exist')
def test_quiet_argument():

    q = Quiet64(one=1, array=[1., -2.2, 3e9], ex_dir=EXAMPLES_DIR)

    assert q.add(-5, 2) == -3
    assert q.kwargs() == {'one': '1', 'array': '[1.0, -2.2, 3000000000.0]', 'ex_dir': EXAMPLES_DIR}


@pytest.mark.skipif(IS_MAC, reason='the 32-bit server for macOS does not exist')
def test_cli_quiet_flag():
    cmd = [os.path.join(os.path.dirname(__file__), os.pardir, 'msl', 'loadlib', SERVER_FILENAME), '--quiet']
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()

    assert out.rstrip() == b'DeprecationWarning: the --quiet flag is ignored and will be removed in a future release'
<commit_msg>move comment to test function<commit_after>import os
import subprocess

try:
    import pytest
except ImportError:  # the 32-bit server does not need pytest installed
    class Mark(object):
        @staticmethod
        def skipif(condition, reason=None):
            def func(function):
                return function
            return func

    class pytest(object):
        mark = Mark

from msl.loadlib import Server32, Client64, SERVER_FILENAME, IS_MAC
from msl.examples.loadlib import EXAMPLES_DIR


class Quiet32(Server32):

    def __init__(self, host, port, quiet, **kwargs):
        super(Quiet32, self).__init__(
            os.path.join(kwargs['ex_dir'], 'cpp_lib32'),
            'cdll', host, port, quiet
        )
        self._kwargs = kwargs

    def add(self, a, b):
        return self.lib.add(a, b)

    def kwargs(self):
        return self._kwargs


class Quiet64(Client64):

    def __init__(self, **kwargs):
        super(Quiet64, self).__init__(__file__, **kwargs)

    def add(self, a, b):
        # a and b must be integers
        return self.request32('add', a, b)

    def kwargs(self):
        return self.request32('kwargs')


@pytest.mark.skipif(IS_MAC, reason='the 32-bit server for macOS does not exist')
def test_quiet_argument():
    # Make sure that the old syntax where Server32 required a `quiet` argument is still valid.
    q = Quiet64(one=1, array=[1., -2.2, 3e9], ex_dir=EXAMPLES_DIR)
    assert q.add(-5, 2) == -3
    assert q.kwargs() == {'one': '1', 'array': '[1.0, -2.2, 3000000000.0]', 'ex_dir': EXAMPLES_DIR}


@pytest.mark.skipif(IS_MAC, reason='the 32-bit server for macOS does not exist')
def test_cli_quiet_flag():
    cmd = [os.path.join(os.path.dirname(__file__), os.pardir, 'msl', 'loadlib', SERVER_FILENAME), '--quiet']
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()

    assert out.rstrip() == b'DeprecationWarning: the --quiet flag is ignored and will be removed in a future release'

{'fraction_non_alphanumeric': 0.12705941088367448, 'fraction_numerical': 0.028457314028956564, 'mean_word_length': 3.055668016194332, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6247710', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1326, 'n_words': 377}