<commit_before># -*- coding: utf-8 -*-
import pytest

from fake_fs import make_fake_fstools
from teuthology.describe_tests import tree_with_info, extract_info
from teuthology.exceptions import ParseError

realistic_fs = {
    'basic': {
        '%': None,
        'base': {
            'install.yaml':
            """description:
- desc: install ceph
install:
"""
        },
        'clusters': {
            'fixed-1.yaml':
            """description:
- desc: single node cluster
roles:
- [osd.0, osd.1, osd.2, mon.a, mon.b, mon.c, client.0]
"""
        },
        'workloads': {
            'rbd_api_tests_old_format.yaml':
            """description:
- desc: c/c++ librbd api tests with format 1 images
  rbd_features: none
overrides:
  ceph:
    conf:
      client:
        rbd default format: 1
tasks:
- workunit:
    env:
      RBD_FEATURES: 0
    clients:
      client.0:
        - rbd/test_librbd.sh
""",
            'rbd_api_tests.yaml':
            """description:
- desc: c/c++ librbd api tests with default settings
  rbd_features: default
tasks:
- workunit:
    clients:
      client.0:
        - rbd/test_librbd.sh
""",
        },
    },
}


expected_tree = """├── %
├── base
│   └── install.yaml
├── clusters
│   └── fixed-1.yaml
└── workloads
    ├── rbd_api_tests.yaml
    └── rbd_api_tests_old_format.yaml""".split('\n')


expected_facets = [
    '',
    '',
    'base',
    '',
    'clusters',
    '',
    'workloads',
    'workloads',
]


expected_desc = [
    '',
    '',
    'install ceph',
    '',
    'single node cluster',
    '',
    'c/c++ librbd api tests with default settings',
    'c/c++ librbd api tests with format 1 images',
]


expected_rbd_features = [
    '',
    '',
    '',
    '',
    '',
    '',
    'default',
    'none',
]


class TestDescribeTests(object):

    def setup(self):
        self.fake_listdir, _, self.fake_isdir, self.fake_open = \
            make_fake_fstools(realistic_fs)

    def test_no_filters(self):
        rows = tree_with_info('basic', [], False, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == [ [x] for x in expected_tree]

    def test_single_filter(self):
        rows = tree_with_info('basic', ['desc'], False, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == map(list, zip(expected_tree, expected_desc))

        rows = tree_with_info('basic', ['rbd_features'], False, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == map(list, zip(expected_tree, expected_rbd_features))

    def test_single_filter_with_facets(self):
        rows = tree_with_info('basic', ['desc'], True, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == map(list, zip(expected_tree, expected_facets,
                                     expected_desc))

        rows = tree_with_info('basic', ['rbd_features'], True, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == map(list, zip(expected_tree, expected_facets,
                                     expected_rbd_features))

    def test_no_matching(self):
        fake_listdir, _, fake_isdir, fake_open = \
            make_fake_fstools(realistic_fs)
        rows = tree_with_info('basic', ['extra'], False, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == map(list, zip(expected_tree, [''] * len(expected_tree)))

        rows = tree_with_info('basic', ['extra'], True, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == map(list, zip(expected_tree, expected_facets,
                                     [''] * len(expected_tree)))

    def test_multiple_filters(self):
        fake_listdir, _, fake_isdir, fake_open = \
            make_fake_fstools(realistic_fs)
        rows = tree_with_info('basic', ['desc', 'rbd_features'], False,
                              '', [], self.fake_listdir,
                              self.fake_isdir, self.fake_open)
        assert rows == map(list, zip(expected_tree,
                                     expected_desc,
                                     expected_rbd_features))

        rows = tree_with_info('basic', ['rbd_features', 'desc'], False,
                              '', [], self.fake_listdir,
                              self.fake_isdir, self.fake_open)
        assert rows == map(list, zip(expected_tree,
                                     expected_rbd_features,
                                     expected_desc))


    def test_multiple_filters_with_facets(self):
        rows = tree_with_info('basic', ['desc', 'rbd_features'], True,
                              '', [], self.fake_listdir,
                              self.fake_isdir, self.fake_open)
        assert rows == map(list, zip(expected_tree,
                                     expected_facets,
                                     expected_desc,
                                     expected_rbd_features))

        rows = tree_with_info('basic', ['rbd_features', 'desc'], True,
                              '', [], self.fake_listdir,
                              self.fake_isdir, self.fake_open)
        assert rows == map(list, zip(expected_tree,
                                     expected_facets,
                                     expected_rbd_features,<commit_msg>test-describe-tests: remove unnecessary vars<commit_after># -*- coding: utf-8 -*-
import pytest

from fake_fs import make_fake_fstools
from teuthology.describe_tests import tree_with_info, extract_info
from teuthology.exceptions import ParseError

realistic_fs = {
    'basic': {
        '%': None,
        'base': {
            'install.yaml':
            """description:
- desc: install ceph
install:
"""
        },
        'clusters': {
            'fixed-1.yaml':
            """description:
- desc: single node cluster
roles:
- [osd.0, osd.1, osd.2, mon.a, mon.b, mon.c, client.0]
"""
        },
        'workloads': {
            'rbd_api_tests_old_format.yaml':
            """description:
- desc: c/c++ librbd api tests with format 1 images
  rbd_features: none
overrides:
  ceph:
    conf:
      client:
        rbd default format: 1
tasks:
- workunit:
    env:
      RBD_FEATURES: 0
    clients:
      client.0:
        - rbd/test_librbd.sh
""",
            'rbd_api_tests.yaml':
            """description:
- desc: c/c++ librbd api tests with default settings
  rbd_features: default
tasks:
- workunit:
    clients:
      client.0:
        - rbd/test_librbd.sh
""",
        },
    },
}


expected_tree = """├── %
├── base
│   └── install.yaml
├── clusters
│   └── fixed-1.yaml
└── workloads
    ├── rbd_api_tests.yaml
    └── rbd_api_tests_old_format.yaml""".split('\n')


expected_facets = [
    '',
    '',
    'base',
    '',
    'clusters',
    '',
    'workloads',
    'workloads',
]


expected_desc = [
    '',
    '',
    'install ceph',
    '',
    'single node cluster',
    '',
    'c/c++ librbd api tests with default settings',
    'c/c++ librbd api tests with format 1 images',
]


expected_rbd_features = [
    '',
    '',
    '',
    '',
    '',
    '',
    'default',
    'none',
]


class TestDescribeTests(object):

    def setup(self):
        self.fake_listdir, _, self.fake_isdir, self.fake_open = \
            make_fake_fstools(realistic_fs)

    def test_no_filters(self):
        rows = tree_with_info('basic', [], False, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == [ [x] for x in expected_tree]

    def test_single_filter(self):
        rows = tree_with_info('basic', ['desc'], False, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == map(list, zip(expected_tree, expected_desc))

        rows = tree_with_info('basic', ['rbd_features'], False, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == map(list, zip(expected_tree, expected_rbd_features))

    def test_single_filter_with_facets(self):
        rows = tree_with_info('basic', ['desc'], True, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == map(list, zip(expected_tree, expected_facets,
                                     expected_desc))

        rows = tree_with_info('basic', ['rbd_features'], True, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == map(list, zip(expected_tree, expected_facets,
                                     expected_rbd_features))

    def test_no_matching(self):
        rows = tree_with_info('basic', ['extra'], False, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == map(list, zip(expected_tree, [''] * len(expected_tree)))

        rows = tree_with_info('basic', ['extra'], True, '', [],
                              self.fake_listdir, self.fake_isdir,
                              self.fake_open)
        assert rows == map(list, zip(expected_tree, expected_facets,
                                     [''] * len(expected_tree)))

    def test_multiple_filters(self):
        rows = tree_with_info('basic', ['desc', 'rbd_features'], False,
                              '', [], self.fake_listdir,
                              self.fake_isdir, self.fake_open)
        assert rows == map(list, zip(expected_tree,
                                     expected_desc,
                                     expected_rbd_features))

        rows = tree_with_info('basic', ['rbd_features', 'desc'], False,
                              '', [], self.fake_listdir,
                              self.fake_isdir, self.fake_open)
        assert rows == map(list, zip(expected_tree,
                                     expected_rbd_features,
                                     expected_desc))


    def test_multiple_filters_with_facets(self):
        rows = tree_with_info('basic', ['desc', 'rbd_features'], True,
                              '', [], self.fake_listdir,
                              self.fake_isdir, self.fake_open)
        assert rows == map(list, zip(expected_tree,
                                     expected_facets,
                                     expected_desc,
                                     expected_rbd_features))

        rows = tree_with_info('basic', ['rbd_features', 'desc'], True,
                              '', [], self.fake_listdir,
                              self.fake_isdir, self.fake_open)
        assert rows == map(list, zip(expected_tree,
                                     expected_facets,
                                     expected_rbd_features,
{'fraction_non_alphanumeric': 0.12278848692896752, 'fraction_numerical': 0.002288530939177889, 'mean_word_length': 1.5705882352941176, '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': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1353013', 'n_tokens_mistral': 3318, 'n_tokens_neox': 3316, 'n_words': 614}