<commit_before># encoding: utf-8

from __future__ import unicode_literals

from unittest import TestCase

try:
    from pathlib import Path
    HAS_PATHLIB = True
except ImportError:
    HAS_PATHLIB = False

from pyinfra.api.connectors.util import (
    escape_unix_path,
    make_unix_command,
    split_combined_output,
)


class TestConnectorUtil(TestCase):
    def test_split_combined_output_works(self):
        results = split_combined_output([
            ('stdout', 'stdout1'),
            ('stdout', 'stdout2'),
            ('stderr', 'stderr1'),
            ('stdout', 'stdout3'),
        ])

        assert results == (['stdout1', 'stdout2', 'stdout3'], ['stderr1'])

    def test_split_combined_output_raises(self):
        with self.assertRaises(ValueError):
            split_combined_output(['nope', ''])


class TestEscapeUnixPathUtil(TestCase):
    def test_path(self):
        escaped_path = escape_unix_path('/path/to/directory with space/ starts')
        assert escaped_path == '/path/to/directory\\ with\\ space/\\ starts'

    def test_escaped_path(self):
        escaped_path = '/path/to/directory\\ with\\ space/\\ starts'
        double_escaped_path = escape_unix_path(escaped_path)
        assert double_escaped_path == escaped_path

    def test_pathlib_path(self):
        if not HAS_PATHLIB:
            return

        path = Path('/', 'path', 'to', 'directory with space', ' starts')
        escaped_path = escape_unix_path(path)
        assert escaped_path == '/path/to/directory\\ with\\ space/\\ starts'
<commit_msg>Use `PurePosixPath` when testing `ensure_unix_path`.<commit_after># encoding: utf-8

from __future__ import unicode_literals

from unittest import TestCase

try:
    from pathlib import PurePosixPath
    HAS_PATHLIB = True
except ImportError:
    HAS_PATHLIB = False

from pyinfra.api.connectors.util import (
    escape_unix_path,
    make_unix_command,
    split_combined_output,
)


class TestConnectorUtil(TestCase):
    def test_split_combined_output_works(self):
        results = split_combined_output([
            ('stdout', 'stdout1'),
            ('stdout', 'stdout2'),
            ('stderr', 'stderr1'),
            ('stdout', 'stdout3'),
        ])

        assert results == (['stdout1', 'stdout2', 'stdout3'], ['stderr1'])

    def test_split_combined_output_raises(self):
        with self.assertRaises(ValueError):
            split_combined_output(['nope', ''])


class TestEscapeUnixPathUtil(TestCase):
    def test_path(self):
        escaped_path = escape_unix_path('/path/to/directory with space/ starts')
        assert escaped_path == '/path/to/directory\\ with\\ space/\\ starts'

    def test_escaped_path(self):
        escaped_path = '/path/to/directory\\ with\\ space/\\ starts'
        double_escaped_path = escape_unix_path(escaped_path)
        assert double_escaped_path == escaped_path

    def test_pathlib_path(self):
        if not HAS_PATHLIB:
            return

        path = PurePosixPath('/', 'path', 'to', 'directory with space', ' starts')
        escaped_path = escape_unix_path(path)
        assert escaped_path == '/path/to/directory\\ with\\ space/\\ starts'

{'fraction_non_alphanumeric': 0.11870845204178537, 'fraction_numerical': 0.005698005698005698, 'mean_word_length': 3.0, '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': '346541', 'n_tokens_mistral': 982, 'n_tokens_neox': 955, 'n_words': 208}