<commit_before>#!/usr/bin/env python


# Copyright (C) 2015 Intel Corporation
#
# Released under the MIT license (see COPYING.MIT)
# ./runtest.py -b build_data.json -a tag -f test.manifest

import sys
import os
import time
import unittest
import inspect
from optparse import OptionParser
from oeqa.oetest import oeTest
from oeqa.oetest import oeRuntimeTest
from oeqa.oetest import runTests
from oeqa.runexported import FakeTarget
from oeqa.runexported import MyDataDict
from oeqa.runexported import TestContext
from oeqa.utils.sshcontrol import SSHControl

try:
    import simplejson as json
except ImportError:
    import json

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "oeqa")))

def check_tag(tcase, taglist):
    """ check if test method has specified tag enabled """
    if not hasattr(tcase, "_testMethodName"):
        return False
    tc_method = getattr(tcase, tcase._testMethodName)
    for tag in taglist:
        if hasattr(tc_method, tag):
            return True
    return check_tag_class(tcase, taglist)

def check_tag_class(tcase, taglist):
    """ check if test class has specified tag enabled """
    if not hasattr(tcase, "_testMethodName"):
        return False
    tc_method = getattr(tcase, tcase._testMethodName)
    tc_class = tc_method.__self__.__class__
    for tag in taglist:
        if hasattr(tc_class, tag):
            return True
    return False

def runTests_tag(tc, taglist):
    """ run whole test suite according to tclist"""
    # set the context object passed from the test class
    setattr(oeTest, "tc", tc)
    # set ps command to use
    setattr(oeRuntimeTest, "pscmd", "ps -ef" if oeTest.hasPackage("procps") else "ps")
    # prepare test suite, loader and runner
    suite = unittest.TestSuite()
    testloader = unittest.TestLoader()
    testloader.sortTestMethodsUsing = None
    for tname in tc.testslist:
        tsuite = testloader.loadTestsFromName(tname)
        for ts in tsuite:
            # it is test suite
            if hasattr(ts, "_tests"):
                if ts._tests and check_tag_class(ts._tests[0], taglist):
                    print "add suite"
                    suite.addTest(ts)
                else:
                    for x in ts._tests:
                        if check_tag(x, taglist):
                            suite.addTest(x)
            # it is test case
            else:
                if check_tag(ts, taglist):
                    suite.addTest(ts)
    print("Test modules  %s" % tc.testslist)
    print("Found %s tests" % suite.countTestCases())
    runner = unittest.TextTestRunner(verbosity=2)
    result = runner.run(suite)
    return result

def main():

    usage = "usage: %prog [options]"<commit_msg>[TestRunner] Support advanced tag format key=value for filter<commit_after>#!/usr/bin/env python


# Copyright (C) 2015 Intel Corporation
#
# Released under the MIT license (see COPYING.MIT)
# ./runtest.py -b build_data.json -a tag -f test.manifest

import sys
import os
import time
import unittest
import inspect
from optparse import OptionParser
from oeqa.oetest import oeTest
from oeqa.oetest import oeRuntimeTest
from oeqa.oetest import runTests
from oeqa.runexported import FakeTarget
from oeqa.runexported import MyDataDict
from oeqa.runexported import TestContext
from oeqa.utils.sshcontrol import SSHControl

try:
    import simplejson as json
except ImportError:
    import json

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "oeqa")))

def _check(obj, taglist):
    """ match tag inside obj """
    for tag in taglist:
        tkeyval = tag.split("=")
        tkey = tkeyval[0]
        if hasattr(obj, tkey):
            tval = True if len(tkeyval) == 1 else tkeyval[1]
            if tval == getattr(obj, tkey):
                return True
    return False

def check_tag_method(tcase, taglist):
    """ check if test method has specified tag enabled """
    if not hasattr(tcase, "_testMethodName"):
        return False
    tc_method = getattr(tcase, tcase._testMethodName)
    return _check(tc_method, taglist)

def check_tag_class(tcase, taglist):
    """ check if test class has specified tag enabled """
    if not hasattr(tcase, "_testMethodName"):
        return False
    tc_method = getattr(tcase, tcase._testMethodName)
    tc_class = tc_method.__self__.__class__
    return _check(tc_class, taglist)

def runTests_tag(tc, taglist):
    """ run whole test suite according to tclist"""
    # set the context object passed from the test class
    setattr(oeTest, "tc", tc)
    # set ps command to use
    setattr(oeRuntimeTest, "pscmd", "ps -ef" if oeTest.hasPackage("procps") else "ps")
    # prepare test suite, loader and runner
    suite = unittest.TestSuite()
    testloader = unittest.TestLoader()
    testloader.sortTestMethodsUsing = None
    for tname in tc.testslist:
        tsuite = testloader.loadTestsFromName(tname)
        for ts in tsuite:
            # it is test suite
            if hasattr(ts, "_tests") and ts._tests != []:
                if check_tag_class(ts._tests[0], taglist):
                    print "add suite"
                    suite.addTest(ts)
                else:
                    for x in ts._tests:
                        if check_tag_class(x, taglist) or\
                               check_tag_method(x, taglist):
                            suite.addTest(x)
            # it is test case
            else:
                if check_tag_class(ts, taglist) or\
                       check_tag_method(ts, taglist):
                    suite.addTest(ts)
    print("Test modules  %s" % tc.testslist)
    print("Found %s tests" % suite.countTestCases())
    runner = unittest.TextTestRunner(verbosity=2)
    result = runner.run(suite)
    return result

def main():

    usage = "usage: %prog [options]"
{'fraction_non_alphanumeric': 0.09001889709671877, 'fraction_numerical': 0.0025768768252877514, 'mean_word_length': 2.578365089121082, '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': '3460699', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1772, 'n_words': 528}