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

__all__ = ['Command']

import os
import shutil
import json

from .lib import SwaggerParserFactory
from .lib import Printer
from .lib import SDKWriter, DocWriter, CourgetteWriter
from .lib import ModelsProcessor
from .lib import GitManager
from .lib import Utils
from .lib import SwaggerToSpecConverter
from .lib import SpecParser
from .lib import TestsRunner

CODEGEN_DIRECTORY = './codegen'
DOCS_DIRECTORY = './docgen'
SPECGEN_DIRECTORY = './specgen'

API_URL = 'web/docs/api/'


class Command(object):
    """ Command

    """
    @classmethod
    def run_tests(cls, vsdurl, username, password, enterprise, version, data):
        """ Run all tests according to the given data

            `data` contains information:
                `spec`: the specification
                `parent`: the parent information
                `default_values`: the default values for the object

            Args:
                data (dict):

        """
        rest_name = None

        if 'RESTName' in data:
            Printer.log('******* %s' % data['RESTName'])
            rest_name = data['RESTName']

        parent_object = data['parentObject']
        default_values = data['defaultValues']

        spec = data['spec']

        if spec is None or len(spec) == 0:
            spec = Command.get_spec(vsdurl=vsdurl, apiversion=version, rest_name=rest_name)

        processed_spec = ModelsProcessor.process(resources={spec['model']['resouceName']: spec})
        model = processed_spec[spec['model']['resourceName']]

        runner = TestsRunner(vsdurl=vsdurl, username=username, password=password, enterprise=enterprise, version=version, model=model, parent_resource=parent_object['resourceName'], parent_id=parent_object['id'], **default_values)

        return runner.run()

    @classmethod
    def get_spec(cls, vsdurl, apiversion, rest_name, path=None):
        """

        """<commit_msg>Fixed TestRunner run_tests method<commit_after># -*- coding: utf-8 -*-

__all__ = ['Command']

import os
import shutil
import json

from .lib import SwaggerParserFactory
from .lib import Printer
from .lib import SDKWriter, DocWriter, CourgetteWriter
from .lib import ModelsProcessor
from .lib import GitManager
from .lib import Utils
from .lib import SwaggerToSpecConverter
from .lib import SpecParser
from .lib import TestsRunner

CODEGEN_DIRECTORY = './codegen'
DOCS_DIRECTORY = './docgen'
SPECGEN_DIRECTORY = './specgen'

API_URL = 'web/docs/api/'


class Command(object):
    """ Command

    """
    @classmethod
    def run_tests(cls, vsdurl, username, password, enterprise, version, data):
        """ Run all tests according to the given data

            `data` contains information:
                `spec`: the specification
                `parent`: the parent information
                `default_values`: the default values for the object

            Args:
                data (dict):

        """
        rest_name = None

        if 'RESTName' in data:
            Printer.log('******* %s' % data['RESTName'])
            rest_name = data['RESTName']

        parent_object = data['parentObject']
        default_values = data['defaultValues']

        spec = data['spec']

        if spec is None or len(spec) == 0:
            spec = Command.get_spec(vsdurl=vsdurl, apiversion=version, rest_name=rest_name)

        processed_spec = ModelsProcessor.process(resources={spec['model']['RESTName']: spec})
        model = processed_spec[spec['model']['RESTName']]

        runner = TestsRunner(vsdurl=vsdurl, username=username, password=password, enterprise=enterprise, version=version, model=model, parent_resource=parent_object['resourceName'], parent_id=parent_object['id'], **default_values)

        return runner.run()

    @classmethod
    def get_spec(cls, vsdurl, apiversion, rest_name, path=None):
        """

        """
{'fraction_non_alphanumeric': 0.11337284205101777, 'fraction_numerical': 0.001030662200463798, 'mean_word_length': 3.0353430353430353, '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': '312035', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1066, 'n_words': 301}