<commit_before>import os
import sys
lib_path = os.path.abspath('./')
sys.path.insert(0, lib_path)

import unittest
import threading
import time
import mock
import makerbot_driver


class TestBundleProcessorCallbackAssignment(unittest.TestCase):

    def setUp(self):
        self.bp = makerbot_driver.GcodeProcessors.BundleProcessor()
        self.bp._super_process_gcode = mock.Mock(return_value=[])
        self.bp.progress_processor.process_gcode = mock.Mock()

    def tearDown(self):
        self.bp = None

    def test_not_do_progress_no_callback(self):
        self.bp.do_progress = False
        callback = None
        gcodes = []
        self.bp.process_gcode(gcodes, callback)
        self.bp._super_process_gcode.assert_called_once_with([], None)
        self.assertEqual(
            len(self.bp.progress_processor.process_gcode.mock_calls), 0)

    def test_not_do_progress_callback(self):
        self.bp.do_progress = False

        def callback(percent):
            pass
        gcodes = []
        self.bp.process_gcode(gcodes, callback)
        self.bp._super_process_gcode.assert_called_once_with([], callback)
        self.assertEqual(
            len(self.bp.progress_processor.process_gcode.mock_calls), 0)

    def test_do_progress_no_callback(self):
        self.bp.do_progress = True
        callback = None
        gcodes = []
        self.bp.process_gcode(gcodes, callback)
        self.bp._super_process_gcode.assert_called_once_with([], callback)
        self.bp.progress_processor.process_gcode.assert_called_once_with(
            [], None)

    def test_do_progress_callback(self):
        self.bp.do_progress = True

        def callback(percent):
            pass
        gcodes = []
        self.bp.process_gcode(gcodes, callback)
        self.bp._super_process_gcode.assert_called_once_with(
            [], self.bp.new_callback)
        self.bp.progress_processor.process_gcode.assert_called_once_with(
            [], self.bp.progress_callback)


class TestBundleProcessorCallbacks(unittest.TestCase):

    def setUp(self):
        self.condition = threading.Condition()
        self.bp = makerbot_driver.GcodeProcessors.BundleProcessor()
        self.the_percent = 0
        self.percents = []
        self.done_process = False

    def tearDown(self):
        # TRICKY: removed/disabled due to threading failure
        self.bp = None
        self.the_percent = None
        self.percents = None
        self.done_process = None

    def get_percent(self):
        time.sleep(1)
        runner = 0
        while not self.done_process:
            if runner % 1000 == 0:
                if self.percents is not None:
                    self.percents.append(self.the_percent)
            if runner % 10000000 == 0:
                print "."
            runner += 1

    def test_callbacks_with_do_progress(self):
        def test_callback(p):
            self.the_percent = p
        t = threading.Thread(target=self.get_percent)
        path_to_gcode = os.path.join(
            os.path.abspath(os.path.dirname(__file__)),<commit_msg>removed some threading test-code that is not used<commit_after>import os
import sys
lib_path = os.path.abspath('./')
sys.path.insert(0, lib_path)

import unittest
import threading
import time
import mock
import makerbot_driver


class TestBundleProcessorCallbackAssignment(unittest.TestCase):

    def setUp(self):
        self.bp = makerbot_driver.GcodeProcessors.BundleProcessor()
        self.bp._super_process_gcode = mock.Mock(return_value=[])
        self.bp.progress_processor.process_gcode = mock.Mock()

    def tearDown(self):
        self.bp = None

    def test_not_do_progress_no_callback(self):
        self.bp.do_progress = False
        callback = None
        gcodes = []
        self.bp.process_gcode(gcodes, callback)
        self.bp._super_process_gcode.assert_called_once_with([], None)
        self.assertEqual(
            len(self.bp.progress_processor.process_gcode.mock_calls), 0)

    def test_not_do_progress_callback(self):
        self.bp.do_progress = False

        def callback(percent):
            pass
        gcodes = []
        self.bp.process_gcode(gcodes, callback)
        self.bp._super_process_gcode.assert_called_once_with([], callback)
        self.assertEqual(
            len(self.bp.progress_processor.process_gcode.mock_calls), 0)

    def test_do_progress_no_callback(self):
        self.bp.do_progress = True
        callback = None
        gcodes = []
        self.bp.process_gcode(gcodes, callback)
        self.bp._super_process_gcode.assert_called_once_with([], callback)
        self.bp.progress_processor.process_gcode.assert_called_once_with(
            [], None)

    def test_do_progress_callback(self):
        self.bp.do_progress = True

        def callback(percent):
            pass
        gcodes = []
        self.bp.process_gcode(gcodes, callback)
        self.bp._super_process_gcode.assert_called_once_with(
            [], self.bp.new_callback)
        self.bp.progress_processor.process_gcode.assert_called_once_with(
            [], self.bp.progress_callback)


class TestBundleProcessorCallbacks(unittest.TestCase):

    def setUp(self):
        self.bp = makerbot_driver.GcodeProcessors.BundleProcessor()
        self.the_percent = 0
        self.percents = []
        self.done_process = False

    def tearDown(self):
        self.bp = None
        self.the_percent = None
        self.percents = None
        self.done_process = None

    def get_percent(self):
        time.sleep(1)
        runner = 0
        while not self.done_process:
            if runner % 1000 == 0:
                self.percents.append(self.the_percent)
            if runner % 10000000 == 0:
                print "."
            runner += 1

    def test_callbacks_with_do_progress(self):
        def test_callback(p):
            self.the_percent = p
        t = threading.Thread(target=self.get_percent)
        path_to_gcode = os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
{'fraction_non_alphanumeric': 0.09298856290402785, 'fraction_numerical': 0.0069617105917454, 'mean_word_length': 2.448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '1659314', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1804, 'n_words': 299}