<commit_before>##
# Copyright (c) 2017-present MagicStack Inc.
# All rights reserved.
#
# See LICENSE for details.
##


import collections
import edgedb
import flake8  # NoQA
import os
import subprocess
import sys
import textwrap
import unittest

import docutils.nodes
import docutils.parsers
import docutils.utils
import docutils.frontend

from edgedb.lang.edgeql import parser as edgeql_parser
from edgedb.lang.graphql import parser as graphql_parser
from edgedb.lang.schema import parser as schema_parser


class TestFlake8(unittest.TestCase):

    def test_flake8(self):
        edgepath = list(edgedb.__path__)[0]
        edgepath = os.path.dirname(edgepath)

        for subdir in ['edgedb', 'tests']:  # ignore any top-level test files
            try:
                subprocess.run(
                    [sys.executable, '-m', 'flake8'],
                    check=True,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE,
                    cwd=os.path.join(edgepath, subdir))
            except subprocess.CalledProcessError as ex:
                output = ex.output.decode()
                raise AssertionError(
                    f'flake8 validation failed:\n{output}') from None


class TestDocSnippets(unittest.TestCase):
    """Lint and validate EdgeDB documentation files.

    Checks:

    * all source code in "code-block" directives is parsed to<commit_msg>flake8: Fix flake8 test to explicitly set the config file<commit_after>##
# Copyright (c) 2017-present MagicStack Inc.
# All rights reserved.
#
# See LICENSE for details.
##


import collections
import edgedb
import flake8  # NoQA
import os
import subprocess
import sys
import textwrap
import unittest

import docutils.nodes
import docutils.parsers
import docutils.utils
import docutils.frontend

from edgedb.lang.edgeql import parser as edgeql_parser
from edgedb.lang.graphql import parser as graphql_parser
from edgedb.lang.schema import parser as schema_parser


class TestFlake8(unittest.TestCase):

    def test_flake8(self):
        edgepath = list(edgedb.__path__)[0]
        edgepath = os.path.dirname(edgepath)

        config_path = os.path.join(edgepath, '.flake8')
        for subdir in ['edgedb', 'tests']:  # ignore any top-level test files
            try:
                subprocess.run(
                    [sys.executable, '-m', 'flake8', '--config', config_path],
                    check=True,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE,
                    cwd=os.path.join(edgepath, subdir))
            except subprocess.CalledProcessError as ex:
                output = ex.output.decode()
                raise AssertionError(
                    f'flake8 validation failed:\n{output}') from None


class TestDocSnippets(unittest.TestCase):
    """Lint and validate EdgeDB documentation files.

    Checks:

    * all source code in "code-block" directives is parsed to
{'fraction_non_alphanumeric': 0.08195055875380969, 'fraction_numerical': 0.0077886894683372844, 'mean_word_length': 2.5292712066905616, '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': '2194293', 'n_tokens_mistral': 877, 'n_tokens_neox': 830, 'n_words': 243}