<commit_before>"""
Converts a Selenium IDE WebDriver-exported test file into a SeleniumBase file

Usage:
python convert_ide.py [MY_TEST.py]
Output:
[MY_TEST_SB.py]  (Adds "_SB" to the file name)
"""

import codecs
import re
import sys


def main():
    expected_arg = "[A Selenium IDE recording exported to Python WebDriver]"
    num_args = len(sys.argv)
    if num_args < 2 or num_args > 2:
        raise Exception("\n* INVALID RUN COMMAND! *  Usage:\n"
                        "python convert_ide.py %s\n" % expected_arg)
    elif num_args == 2:
        if not sys.argv[1].endswith('.py'):
            raise Exception("Not a Python file!")
    webdriver_python_file = sys.argv[1]

    seleniumbase_lines = []
    seleniumbase_lines.append("from seleniumbase import BaseCase")
    seleniumbase_lines.append("")  # Flake8 is very specific on whitespace
    seleniumbase_lines.append("")

    ide_base_url = ""
    in_test_method = False
    has_unicode = False

    f = open(webdriver_python_file, 'r')
    all_code = f.read()
    f.close()
    if "def test_" not in all_code:
        raise Exception("Not a valid Python unittest.TestCase file!")
    code_lines = all_code.split('\n')
    for line in code_lines:

        # Handle utf-8 encoding if present
        data = re.findall('^\s*# -\*- coding: utf-8 -\*-\s*$', line)
        if data:
            has_unicode = True
            continue

        # Handle class definition
        data = re.findall('^class\s\S+\(unittest\.TestCase\):\s*$', line)
        if data:
            data = data[0].replace("unittest.TestCase", "BaseCase")
            seleniumbase_lines.append(data)
            continue
<commit_msg>Update the Selenium IDE converter script.<commit_after>"""
Converts a Selenium IDE WebDriver-exported test file into a SeleniumBase file

Usage:
python convert_ide.py [MY_TEST.py]
Output:
[MY_TEST_SB.py]  (Adds "_SB" to the file name)
"""

import codecs
import re
import sys


def main():
    expected_arg = "[A Selenium IDE recording exported to Python WebDriver]"
    num_args = len(sys.argv)
    if num_args < 2 or num_args > 2:
        raise Exception("\n* INVALID RUN COMMAND! *  Usage:\n"
                        "python convert_ide.py %s\n" % expected_arg)
    elif num_args == 2:
        if not sys.argv[1].endswith('.py'):
            raise Exception("Not a Python file!")
    webdriver_python_file = sys.argv[1]

    seleniumbase_lines = []
    seleniumbase_lines.append("from seleniumbase import BaseCase")
    seleniumbase_lines.append("")  # Flake8 is very specific on whitespace
    seleniumbase_lines.append("")

    ide_base_url = ""
    in_test_method = False
    has_unicode = False

    f = open(webdriver_python_file, 'r')
    all_code = f.read()
    f.close()
    if "def test_" not in all_code:
        raise Exception("Not a valid Python unittest.TestCase file!")
    code_lines = all_code.split('\n')
    for line in code_lines:

        # Handle utf-8 encoding if present
        data = re.findall('^\s*# -\*- coding: utf-8 -\*-\s*$', line)
        if data:
            has_unicode = True
            continue

        # Keep SeleniumBase classes if already used in the test script
        data = re.findall('^class\s\S+\(BaseCase\):\s*$', line)
        if data:
            seleniumbase_lines.append(line)
            continue

        # Have unittest.TestCase classes inherit BaseCase instead
        data = re.findall('^class\s\S+\(unittest\.TestCase\):\s*$', line)
        if data:
            data = data[0].replace("unittest.TestCase", "BaseCase")
            seleniumbase_lines.append(data)
            continue

{'fraction_non_alphanumeric': 0.11578947368421053, 'fraction_numerical': 0.004986149584487534, 'mean_word_length': 2.5541338582677167, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '963039', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1120, 'n_words': 313}