<commit_before>from penchy.compat import unittest
from penchy.jobs import *


class JobClientElementsTest(unittest.TestCase):
    def test_timeout_factor_int(self):
        ns = NodeSetting('localhost', 22, 'dummy', '/', '/', timeout_factor=5)
        self.assertEqual(ns.timeout_factor, 5)

    def test_timeout_factor_func(self):
        ns = NodeSetting('localhost', 22, 'dummy', '/', '/',
                timeout_factor=lambda: 6)
        self.assertEqual(ns.timeout_factor, 6)

    def test_jvm_no_timeout(self):
        j = jvms.JVM('java')
        w = workloads.ScalaBench('dummy')
        self.assertEqual(j.timeout, 0)
        j.workload = w
        self.assertEqual(j.timeout, 0)

    def test_jvm_timeout(self):
        j = jvms.JVM('java', timeout_factor=2)
        j.workload = workloads.ScalaBench('dummy', timeout=10)
        self.assertEqual(j.timeout, 20)

    def test_comp_timeout(self):
        n = NodeSetting('localhost', 22, 'dummy', '/', '/', timeout_factor=2)
        j = jvms.JVM('java', timeout_factor=2)
        j.workload = workloads.ScalaBench('dummy', timeout=10)
        c = SystemComposition(j, n)
        self.assertEqual(c.timeout, 40)

    def test_hooks(self):
        n = NodeSetting('localhost', 22, 'dummy', '/', '/', timeout_factor=2)
        j = jvms.JVM('java', timeout_factor=2)
        j.workload = workloads.ScalaBench('dummy', timeout=10)
        c = SystemComposition(j, n)
        c.set_timeout_function(lambda x, y: 42)
        self.assertEqual(j.hooks[0].setup(), 42)
        self.assertEqual(j.hooks[0].teardown(), 42)<commit_msg>test hooks with no timeout<commit_after>from penchy.compat import unittest
from penchy.jobs import *


class JobClientElementsTest(unittest.TestCase):
    def test_timeout_factor_int(self):
        ns = NodeSetting('localhost', 22, 'dummy', '/', '/', timeout_factor=5)
        self.assertEqual(ns.timeout_factor, 5)

    def test_timeout_factor_func(self):
        ns = NodeSetting('localhost', 22, 'dummy', '/', '/',
                timeout_factor=lambda: 6)
        self.assertEqual(ns.timeout_factor, 6)

    def test_jvm_no_timeout(self):
        j = jvms.JVM('java')
        w = workloads.ScalaBench('dummy')
        self.assertEqual(j.timeout, 0)
        j.workload = w
        self.assertEqual(j.timeout, 0)

    def test_jvm_timeout(self):
        j = jvms.JVM('java', timeout_factor=2)
        j.workload = workloads.ScalaBench('dummy', timeout=10)
        self.assertEqual(j.timeout, 20)

    def test_comp_timeout(self):
        n = NodeSetting('localhost', 22, 'dummy', '/', '/', timeout_factor=2)
        j = jvms.JVM('java', timeout_factor=2)
        j.workload = workloads.ScalaBench('dummy', timeout=10)
        c = SystemComposition(j, n)
        self.assertEqual(c.timeout, 40)

    def test_hooks(self):
        n = NodeSetting('localhost', 22, 'dummy', '/', '/', timeout_factor=2)
        j = jvms.JVM('java', timeout_factor=2)
        j.workload = workloads.ScalaBench('dummy', timeout=10)
        c = SystemComposition(j, n)
        c.set_timeout_function(lambda x, y: 42)
        self.assertEqual(j.hooks[0].setup(), 42)
        self.assertEqual(j.hooks[0].teardown(), 42)

    def test_no_timeout(self):
        n = NodeSetting('localhost', 22, 'dummy', '/', '/')
        j = jvms.JVM('java')
        j.workload = workloads.ScalaBench('dummy')
        c = SystemComposition(j, n)
        c.set_timeout_function(lambda x, y: 42)
        self.assertEqual(j.hooks, [])
        self.assertEqual(j.hooks, [])
{'fraction_non_alphanumeric': 0.1487603305785124, 'fraction_numerical': 0.022228555143915644, 'mean_word_length': 2.921787709497207, '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': '333336', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1153, 'n_words': 206}