<commit_before>import unittest
import time
import os
import tempfile
import shutil
import random
from pabot import pabotlib
from robot.libraries.BuiltIn import BuiltIn
from robot.running.context import EXECUTION_CONTEXTS
from robot.running.namespace import Namespace
from robot.running.model import TestSuite
from robot.output import Output
from robot.variables import Variables

class PabotLibTests(unittest.TestCase):

    def setUp(self):
        builtinmock = lambda:0
        builtinmock.get_variable_value = lambda *args:None
        self._runs = 0
        def runned(*args):
            self._runs += 1
        builtinmock.run_keyword = runned
        pabotlib.BuiltIn = lambda:builtinmock
        self.builtinmock = builtinmock

    def test_pabotlib_listener_path(self):
        lib = pabotlib.PabotLib()
        lib._start_suite('Suite', {'longname':'Suite'})
        self.assertEqual(lib._path, 'Suite')
        lib._start_test('Test', {'longname':'Suite.Test'})
        self.assertEqual(lib._path, 'Suite.Test')
        lib._start_keyword('Keyword1', {})
        self.assertEqual(lib._path, 'Suite.Test.0')
        lib._end_keyword('Keyword1', {})
        lib._start_keyword('Keyword2', {})
        self.assertEqual(lib._path, 'Suite.Test.1')
        lib._end_keyword('Keyword2', {})
        self.assertEqual(lib._path, 'Suite.Test')
        lib._end_test('Test', {})
        self.assertEqual(lib._path, 'Suite')
        lib._end_suite('Suite', {})
        self.assertEqual(lib._path, '')
        lib._close()

    def test_pabotlib_set_get_parallel_value(self):
        lib = pabotlib.PabotLib()
        lib.set_parallel_value_for_key("key", 1)
        value = lib.get_parallel_value_for_key("key")
        self.assertEqual(value, 1)

    def test_pabotlib_run_only_once(self):
        lib = pabotlib.PabotLib()
        self.assertEqual(self._runs, 0)
        lib.run_only_once("keyword")
        self.assertEqual(self._runs, 1)
        lib.run_only_once("keyword")
        self.assertEqual(self._runs, 1)

    def test_pabotlib_run_on_last_process(self):
        lib = pabotlib.PabotLib()
        self.assertEqual(self._runs, 0)
        self.builtinmock.get_variable_value = lambda *args:'0'
        lib.run_on_last_process("keyword")
        self.assertEqual(self._runs, 0)
        self.builtinmock.get_variable_value = lambda *args:'1'
        lib.get_parallel_value_for_key = lambda *args: 1
        lib.run_on_last_process("keyword")
        self.assertEqual(self._runs, 1)<commit_msg>test for pabotlib dynamic import<commit_after>import unittest
import time
import os
import tempfile
import shutil
import random
from pabot import pabotlib
from robot.libraries.BuiltIn import BuiltIn
from robot.running.context import EXECUTION_CONTEXTS
from robot.running.namespace import Namespace
from robot.running.model import TestSuite
from robot.output import Output
from robot.variables import Variables

class PabotLibTests(unittest.TestCase):

    def setUp(self):
        builtinmock = lambda:0
        builtinmock.get_variable_value = lambda *args:None
        self._runs = 0
        def runned(*args):
            self._runs += 1
        builtinmock.run_keyword = runned
        pabotlib.BuiltIn = lambda:builtinmock
        self.builtinmock = builtinmock

    def test_pabotlib_listener_path(self):
        lib = pabotlib.PabotLib()
        lib._start_suite('Suite', {'longname':'Suite'})
        self.assertEqual(lib._path, 'Suite')
        lib._start_test('Test', {'longname':'Suite.Test'})
        self.assertEqual(lib._path, 'Suite.Test')
        lib._start_keyword('Keyword1', {})
        self.assertEqual(lib._path, 'Suite.Test.0')
        lib._end_keyword('Keyword1', {})
        lib._start_keyword('Keyword2', {})
        self.assertEqual(lib._path, 'Suite.Test.1')
        lib._end_keyword('Keyword2', {})
        self.assertEqual(lib._path, 'Suite.Test')
        lib._end_test('Test', {})
        self.assertEqual(lib._path, 'Suite')
        lib._end_suite('Suite', {})
        self.assertEqual(lib._path, '')
        lib._close()

    def test_pabotlib_listener_when_dynamic_import_with_import_library(self):
        lib = pabotlib.PabotLib()
        lib._end_keyword('Import Library', {})
        self.assertEqual(lib._path, '')
        lib._start_keyword('Some Keyword', {})
        self.assertEqual(lib._path, '.1')
        lib._end_keyword('Some Keyword', {})
        self.assertEqual(lib._path, '')
        lib._end_test('Test', {})
        self.assertEqual(lib._path, '')
        lib._end_suite('Suite', {})
        self.assertEqual(lib._path, '')
        lib._close()

    def test_pabotlib_set_get_parallel_value(self):
        lib = pabotlib.PabotLib()
        lib.set_parallel_value_for_key("key", 1)
        value = lib.get_parallel_value_for_key("key")
        self.assertEqual(value, 1)

    def test_pabotlib_run_only_once(self):
        lib = pabotlib.PabotLib()
        self.assertEqual(self._runs, 0)
        lib.run_only_once("keyword")
        self.assertEqual(self._runs, 1)
        lib.run_only_once("keyword")
        self.assertEqual(self._runs, 1)

    def test_pabotlib_run_on_last_process(self):
        lib = pabotlib.PabotLib()
        self.assertEqual(self._runs, 0)
        self.builtinmock.get_variable_value = lambda *args:'0'
        lib.run_on_last_process("keyword")
        self.assertEqual(self._runs, 0)
        self.builtinmock.get_variable_value = lambda *args:'1'
        lib.get_parallel_value_for_key = lambda *args: 1
        lib.run_on_last_process("keyword")
        self.assertEqual(self._runs, 1)
{'fraction_non_alphanumeric': 0.118491921005386, 'fraction_numerical': 0.007360861759425494, 'mean_word_length': 3.0516363636363635, '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': '2606337', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1768, 'n_words': 288}