<commit_before>#!/usr/bin/env python
#  Copyright 2008-2011 Nokia Siemens Networks Oyj
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
import optparse
import os
import random
import shutil
import sys
import sqlite3
from sqlite3 import OperationalError
import copy
from time import strftime, time
import urllib2

ROOT = os.path.dirname(__file__)
lib = os.path.join(ROOT, '..', 'lib')
src = os.path.join(ROOT, '..', 'src')

sys.path.insert(0, lib)
sys.path.insert(0, src)

class Randomizer():

    def __init__(self, seed=None):
        self.random = random.Random()
        if not seed:
            self.seed = int(time())
        else:
            self.seed = int(seed)
        self.random.seed(self.seed)
        self.len_of_words = len(words)
        self.len_of_verbs = len(verbs)

    def get_seed(self):
        return self.seed

    def _choice(self, theArray, capitalize=False, prefix=""):
        chosen = theArray[self.random.randint(0, len(theArray)-1)]
        if type(chosen) is tuple:
            return chosen
        if capitalize:
            chosen = chosen.capitalize()
        return "%s%s" % (prefix, chosen)

    def _get_random_name(self, prefix=""):
        return self._choice(words, capitalize=True, prefix=prefix)
        #random_name = words[self.random.randint(0,self.len_of_words-1)].strip().capitalize()
        #return "%s%s" % (prefix, random_name)

    def _get_random_verb(self, prefix=""):
        return self._choice(verbs, capitalize=False, prefix=prefix)
        #verb = verbs[self.random.randint(0, self.len_of_verbs-1)].strip()
        #return "%s%s" % (prefix, verb)

    def _get_random_int(self, start, end):
        return self.random.randint(start,end)

    def _random(self):
        return self.random.random()

class MyParser(optparse.OptionParser):

    def format_epilog(self, formatter):
        return self.epilog
    def format_help(self, formatter=None):
        if formatter is None:
            formatter = self.formatter
        result = []
        if self.usage:
            result.append(self.get_usage() + "\n")
        if self.description:
            result.append(self.format_description(formatter) + "\n")
        result.append(self.format_option_help(formatter))
        return "".join(result)

class TestResource:

    def __init__(self, path):
        pass

class TestLibrary:

    def __init__(self, path):
        self.lib_path = path
        self.lib_prefix = "CustomLib"
        self.lib_name = randomizer._get_random_name(self.lib_prefix)
        _sql_execute("INSERT INTO source (path,type) VALUES ('%s','CUSTOMLIBRARY')" % self.lib_name)
        self.lib_file = open("%s/%s.py" % (self.lib_path,self.lib_name),"w")
        self.lib_doc = '\t"""Library documentation:\n' +\
                     '\t\t%s"""' % self.lib_name
        self.write("import os,time\n\n" +\
                  "class %s:\n" % self.lib_name +\
                  "\tdef __init__(self):\n" +\
                  "\t%s\n" % self.lib_doc)
        self.write("\t\t%s" % _select_functionality() + "\n")
        self.verbs = copy.copy(verbs)
        self.kw_count = 1

    def add_keyword(self):
        if len(self.verbs) > 0:
            kw_name_prefix = self.verbs.pop().capitalize()
        else:
            kw_name_prefix = "KW_%d" % self.kw_count
        self.kw_count += 1
        kw_name = kw_name_prefix + "_" + self.lib_prefix
        _sql_execute("INSERT INTO keywords (name,source) VALUES ('%s','%s')" % (kw_name,self.lib_name))
        kw_doc = '"""Keyword documentation for %s"""' % kw_name
        self.write("\tdef %s(self):\n" % kw_name +\
                  "\t\t%s\n" % kw_doc +\
                  "\t\t%s\n" % _select_functionality())

    def write(self, text):
        self.lib_file.write(text)

    def close(self):
        global db_connection

        db_connection.commit()
        self.write("myinstance = %s()" % self.lib_name)
        self.lib_file.close()

class TestSuite(object):

    def __init__(self, path, test_index, available_libraries, avg_test_depth, test_validity, test_count, external_resource_count):
        self.path = path
        self.test_index = test_index
        self.available_libraries = available_libraries
        self.avg_test_depth = avg_test_depth
        self.test_validity = test_validity
        self.test_count = test_count
        self.external_resource_count = external_resource_count<commit_msg>Fix test library keyword naming<commit_after>#!/usr/bin/env python
#  Copyright 2008-2011 Nokia Siemens Networks Oyj
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
import optparse
import os
import random
import shutil
import sys
import sqlite3
from sqlite3 import OperationalError
import copy
from time import strftime, time
import urllib2

ROOT = os.path.dirname(__file__)
lib = os.path.join(ROOT, '..', 'lib')
src = os.path.join(ROOT, '..', 'src')

sys.path.insert(0, lib)
sys.path.insert(0, src)

class Randomizer():

    def __init__(self, seed=None):
        self.random = random.Random()
        if not seed:
            self.seed = int(time())
        else:
            self.seed = int(seed)
        self.random.seed(self.seed)
        self.len_of_words = len(words)
        self.len_of_verbs = len(verbs)

    def get_seed(self):
        return self.seed

    def _choice(self, theArray, capitalize=False, prefix=""):
        chosen = theArray[self.random.randint(0, len(theArray)-1)]
        if type(chosen) is tuple:
            return chosen
        if capitalize:
            chosen = chosen.capitalize()
        return "%s%s" % (prefix, chosen)

    def _get_random_name(self, prefix=""):
        return self._choice(words, capitalize=True, prefix=prefix)
        #random_name = words[self.random.randint(0,self.len_of_words-1)].strip().capitalize()
        #return "%s%s" % (prefix, random_name)

    def _get_random_verb(self, prefix=""):
        return self._choice(verbs, capitalize=False, prefix=prefix)
        #verb = verbs[self.random.randint(0, self.len_of_verbs-1)].strip()
        #return "%s%s" % (prefix, verb)

    def _get_random_int(self, start, end):
        return self.random.randint(start,end)

    def _random(self):
        return self.random.random()

class MyParser(optparse.OptionParser):

    def format_epilog(self, formatter):
        return self.epilog
    def format_help(self, formatter=None):
        if formatter is None:
            formatter = self.formatter
        result = []
        if self.usage:
            result.append(self.get_usage() + "\n")
        if self.description:
            result.append(self.format_description(formatter) + "\n")
        result.append(self.format_option_help(formatter))
        return "".join(result)

class TestResource:

    def __init__(self, path):
        pass

class TestLibrary:

    def __init__(self, path):
        self.lib_path = path
        self.lib_prefix = "CustomLib"
        self.lib_functionality = randomizer._get_random_name()
        self.lib_name = "%s%s" % (self.lib_prefix, self.lib_functionality)
        _sql_execute("INSERT INTO source (path,type) VALUES ('%s','CUSTOMLIBRARY')" % self.lib_name)
        self.lib_file = open("%s/%s.py" % (self.lib_path,self.lib_name),"w")
        self.lib_doc = '\t"""Library documentation:\n' +\
                     '\t\t%s"""' % self.lib_name
        self.write("import os,time\n\n" +\
                  "class %s:\n" % self.lib_name +\
                  "\tdef __init__(self):\n" +\
                  "\t%s\n" % self.lib_doc)
        self.write("\t\t%s" % _select_functionality() + "\n")
        self.verbs = copy.copy(verbs)
        self.kw_count = 1

    def add_keyword(self):
        if len(self.verbs) > 0:
            kw_name_prefix = self.verbs.pop().capitalize()
        else:
            kw_name_prefix = "KW_%d" % self.kw_count
        self.kw_count += 1
        kw_name = kw_name_prefix + "_" + self.lib_functionality
        _sql_execute("INSERT INTO keywords (name,source) VALUES ('%s','%s')" % (kw_name,self.lib_name))
        kw_doc = '"""Keyword documentation for %s"""' % kw_name
        self.write("\tdef %s(self):\n" % kw_name +\
                  "\t\t%s\n" % kw_doc +\
                  "\t\t%s\n" % _select_functionality())

    def write(self, text):
        self.lib_file.write(text)

    def close(self):
        global db_connection

        db_connection.commit()
        self.write("myinstance = %s()" % self.lib_name)
        self.lib_file.close()

class TestSuite(object):

    def __init__(self, path, test_index, available_libraries, avg_test_depth, test_validity, test_count, external_resource_count):
        self.path = path
        self.test_index = test_index
        self.available_libraries = available_libraries
        self.avg_test_depth = avg_test_depth
        self.test_validity = test_validity
        self.test_count = test_count
        self.external_resource_count = external_resource_count
{'fraction_non_alphanumeric': 0.12328352180936995, 'fraction_numerical': 0.005250403877221325, 'mean_word_length': 2.6590321388991502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3118926', 'n_tokens_mistral': 3206, 'n_tokens_neox': 3102, 'n_words': 719}