<commit_before>import collections
import os
import os.path
import sys
import time
import traceback

import yaml

from behave import model, parser, runner
from behave.configuration import Configuration
from behave.formatter.ansi_escapes import escapes
from behave.formatter.pretty_formatter import PrettyFormatter

TAG_HELP = """
Scenarios inherit tags declared on the Feature level. The simplest
TAG_EXPRESSION is simply a tag:

--tags @dev

When a tag in a tag expression starts with a ~, this represents boolean NOT:

--tags ~@dev

A tag expression can have several tags separated by a comma, which represents
logical OR:

--tags @dev,@wip

The --tags option can be specified several times, and this represents logical
AND, for instance this represents the boolean expression
(@foo || !@bar) && @zap:

--tags @foo,~@bar --tags @zap.

Beware that if you want to use several negative tags to exclude several tags
you have to use logical AND:

--tags ~@fixme --tags ~@buggy.

Positive tags can be given a threshold to limit the number of occurrences. Which
can be practical if you are practicing Kanban or CONWIP. This will fail if there
are more than 3 occurrences of the @qa tag:

--tags @qa:3
""".strip()

class Language(object):
    @classmethod
    def load(cls, language_name, default_language_name="en"):
        directory, _f = os.path.split(os.path.abspath(__file__))
        language_path = os.path.join(directory, 'languages.yml')
        languages = yaml.load(open(language_path))
        if language_name not in languages:
            return None
        return cls(languages[language_name], languages[default_language_name])

    def __init__(self, mappings, default_mappings=None):
        self.mappings = mappings
        self.default_mappings = default_mappings

    def words(self, key):
        """
        Give all the synonymns of a word in the requested language
        (or the default language if no word is available).
        """
        if self.default_mappings is not None and key not in self.mappings:
            return self.default_mappings[key].encode('utf').split("|")
        else:
            return self.mappings[key].encode('utf').split("|")

def feature_files(paths):
    files = []
    for path in paths:
        if os.path.isdir(path):
            for dirpath, dirnames, filenames in os.walk(path):
                for filename in filenames:
                    if filename.endswith('.feature'):
                        files.append(os.path.join(dirpath, filename))
        elif path.startswith('@'):
            files.extend([filename.strip() for filename in open(path)])
        elif os.path.exists(path):
            files.append(path)
        else:
            raise Exception("Can't find path: " + path)
    return files

def main():
    config = Configuration()

    if config.tags and config.tags == 'help':
        print TAG_HELP
        sys.exit(0)

    if not config.paths:
        config.paths = ['features']

    passed = []
    failed = []
    undefined = []
    skipped = []

    stream = sys.stdout

    start = os.path.abspath(config.paths[0])
    if not os.path.isdir(start):
        start = os.path.dirname(start)
    while not os.path.isdir(os.path.join(start, 'step_definitions')):
        start = os.path.dirname(start)
        if start == os.getcwd():
            start = None
            break

    if start:
        step_defs_dir = os.path.join(start, 'step_definitions')
        sys.path.insert(0, step_defs_dir)
        for name in os.listdir(step_defs_dir):
            if name.endswith('.py'):
                __import__(name[:-3])
            elif os.path.isdir(os.path.join(step_defs_dir, name)):
                dirname = os.path.join(step_defs_dir, name)
                if os.path.exists(os.path.join(dirname, '__init__.py')):
                    __import__(name)

    context = runner.Context()
    features = []

    for filename in feature_files(config.paths):
        context._push()

        feature = parser.parse_file(os.path.abspath(filename), Language.load('en'))
        features.append(feature)
<commit_msg>Change the step definitions directory from 'step_definitions' to 'steps'.<commit_after>import collections
import os
import os.path
import sys
import time
import traceback

import yaml

from behave import model, parser, runner
from behave.configuration import Configuration
from behave.formatter.ansi_escapes import escapes
from behave.formatter.pretty_formatter import PrettyFormatter

TAG_HELP = """
Scenarios inherit tags declared on the Feature level. The simplest
TAG_EXPRESSION is simply a tag:

--tags @dev

When a tag in a tag expression starts with a ~, this represents boolean NOT:

--tags ~@dev

A tag expression can have several tags separated by a comma, which represents
logical OR:

--tags @dev,@wip

The --tags option can be specified several times, and this represents logical
AND, for instance this represents the boolean expression
(@foo || !@bar) && @zap:

--tags @foo,~@bar --tags @zap.

Beware that if you want to use several negative tags to exclude several tags
you have to use logical AND:

--tags ~@fixme --tags ~@buggy.

Positive tags can be given a threshold to limit the number of occurrences. Which
can be practical if you are practicing Kanban or CONWIP. This will fail if there
are more than 3 occurrences of the @qa tag:

--tags @qa:3
""".strip()

class Language(object):
    @classmethod
    def load(cls, language_name, default_language_name="en"):
        directory, _f = os.path.split(os.path.abspath(__file__))
        language_path = os.path.join(directory, 'languages.yml')
        languages = yaml.load(open(language_path))
        if language_name not in languages:
            return None
        return cls(languages[language_name], languages[default_language_name])

    def __init__(self, mappings, default_mappings=None):
        self.mappings = mappings
        self.default_mappings = default_mappings

    def words(self, key):
        """
        Give all the synonymns of a word in the requested language
        (or the default language if no word is available).
        """
        if self.default_mappings is not None and key not in self.mappings:
            return self.default_mappings[key].encode('utf').split("|")
        else:
            return self.mappings[key].encode('utf').split("|")

def feature_files(paths):
    files = []
    for path in paths:
        if os.path.isdir(path):
            for dirpath, dirnames, filenames in os.walk(path):
                for filename in filenames:
                    if filename.endswith('.feature'):
                        files.append(os.path.join(dirpath, filename))
        elif path.startswith('@'):
            files.extend([filename.strip() for filename in open(path)])
        elif os.path.exists(path):
            files.append(path)
        else:
            raise Exception("Can't find path: " + path)
    return files

def main():
    config = Configuration()

    if config.tags and config.tags == 'help':
        print TAG_HELP
        sys.exit(0)

    if not config.paths:
        config.paths = ['features']

    passed = []
    failed = []
    undefined = []
    skipped = []

    stream = sys.stdout

    start = os.path.abspath(config.paths[0])
    if not os.path.isdir(start):
        start = os.path.dirname(start)
    while not os.path.isdir(os.path.join(start, 'steps')):
        start = os.path.dirname(start)
        if start == os.getcwd():
            start = None
            break

    if start:
        step_defs_dir = os.path.join(start, 'steps')
        sys.path.insert(0, step_defs_dir)
        for name in os.listdir(step_defs_dir):
            if name.endswith('.py'):
                __import__(name[:-3])
            elif os.path.isdir(os.path.join(step_defs_dir, name)):
                dirname = os.path.join(step_defs_dir, name)
                if os.path.exists(os.path.join(dirname, '__init__.py')):
                    __import__(name)

    context = runner.Context()
    features = []

    for filename in feature_files(config.paths):
        context._push()

        feature = parser.parse_file(os.path.abspath(filename), Language.load('en'))
        features.append(feature)

{'fraction_non_alphanumeric': 0.10355317595522025, 'fraction_numerical': 0.0014602092966658554, 'mean_word_length': 2.6464063886424136, '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': '2073175', 'n_tokens_mistral': 2418, 'n_tokens_neox': 2337, 'n_words': 738}