<commit_before>from __future__ import division
import time
try:
    from unittest import mock
except ImportError:
    import mock

from geometry_msgs.msg import PoseStamped
import pygame
import rospy

import beeper


class TestBeeper(object):
    def setup(self):
        self.timeout = 5e-4
        beeper.TIMEOUT = self.timeout
        rospy.init_node("beeper_test", anonymous=True)
        self.beeper = beeper.Beeper()

    def teardown(self):
        pygame.quit()

    def create_pose(self):
        pose = PoseStamped()
        pose.header.stamp = rospy.Time.now()
        return pose

    def make_steady_state(self):
        self.beeper.callback(self.create_pose())

    @mock.patch.object(beeper.Beeper, "beep", autospec=True)
    def test_changing_pose_steady_state(self, mock_beep):
        self.make_steady_state()

        for i in range(21):
            pose = self.create_pose()
            pose.pose.position.x = i
            self.beeper.callback(pose)
            time.sleep(self.timeout / 10)

        assert not mock_beep.called
        assert self.beeper.tracking
        assert self.beeper.last_updated == pose.header.stamp

    @mock.patch.object(beeper.Beeper, "beep", autospec=True)
    def test_not_changing_pose_steady_state(self, mock_beep):
        self.make_steady_state()
        last_change_time = self.beeper.last_updated

        for i in range(21):
            self.beeper.callback(self.create_pose())
            time.sleep(self.timeout / 10)

        assert mock_beep.called
        assert not self.beeper.tracking
        assert self.beeper.last_updated == last_change_time

    @mock.patch.object(beeper.Beeper, "beep", autospec=True)
    def test_tracking_reacquired_steady_state(self, mock_beep):
        self.make_steady_state()
        self.beeper._tracking = False

        time.sleep(self.timeout / 10)
        pose = self.create_pose()
        pose.pose.position.x = 1

        self.beeper.callback(pose)
        assert not mock_beep.called
        assert self.beeper.tracking<commit_msg>Make steady state requires two successive changing poses.<commit_after>from __future__ import division
import time
try:
    from unittest import mock
except ImportError:
    import mock

from geometry_msgs.msg import PoseStamped
import pygame
import rospy

import beeper


class TestBeeper(object):
    def setup(self):
        self.timeout = 5e-4
        beeper.TIMEOUT = self.timeout
        rospy.init_node("beeper_test", anonymous=True)
        self.beeper = beeper.Beeper()

    def teardown(self):
        pygame.quit()

    def create_pose(self):
        pose = PoseStamped()
        pose.header.stamp = rospy.Time.now()
        return pose

    def make_steady_state(self):
        pose = self.create_pose()
        pose.pose.position.x = 1
        self.beeper.callback(pose)
        pose = self.create_pose()
        self.beeper.callback(pose)

    @mock.patch.object(beeper.Beeper, "beep", autospec=True)
    def test_changing_pose_steady_state(self, mock_beep):
        self.make_steady_state()

        for i in range(21):
            pose = self.create_pose()
            pose.pose.position.x = i
            self.beeper.callback(pose)
            time.sleep(self.timeout / 10)

        assert not mock_beep.called
        assert self.beeper.tracking
        assert self.beeper.last_updated == pose.header.stamp

    @mock.patch.object(beeper.Beeper, "beep", autospec=True)
    def test_not_changing_pose_steady_state(self, mock_beep):
        self.make_steady_state()
        last_change_time = self.beeper.last_updated

        for i in range(21):
            self.beeper.callback(self.create_pose())
            time.sleep(self.timeout / 10)

        assert mock_beep.called
        assert not self.beeper.tracking
        assert self.beeper.last_updated == last_change_time

    @mock.patch.object(beeper.Beeper, "beep", autospec=True)
    def test_tracking_reacquired_steady_state(self, mock_beep):
        self.make_steady_state()
        self.beeper._tracking = False

        time.sleep(self.timeout / 10)
        pose = self.create_pose()
        pose.pose.position.x = 1

        self.beeper.callback(pose)
        assert not mock_beep.called
        assert self.beeper.tracking

    # More tests:
    # Changing at start
    # Not changing at start
    # Acquire after not changing at start
    # Empty callback
{'fraction_non_alphanumeric': 0.09153318077803203, 'fraction_numerical': 0.006178489702517162, 'mean_word_length': 2.5364077669902914, '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': '5737304', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1361, 'n_words': 274}