<commit_before>#! /usr/bin/env python
#encoding: utf8
import rospy, unittest, rostest
import rosnode
import time
from pimouse_ros.msg import LightSensorValues 

class LightsensorTest(unittest.TestCase):
    def setUp(self):
        self.count = 0
        rospy.Subscriber('/lightsensors', LightSensorValues, self.callback)
        self.values = LightSensorValues()

    def callback(self,data):
        self.count += 1
        self.values = data
    
    def check_values(self,lf,ls,rs,rf):
        vs = self.values
        self.assertEqual(vs.left_forward, lf, "different value: left_forward")
        self.assertEqual(vs.left_side, ls, "different value: left_side")
        self.assertEqual(vs.right_side, rs, "different value: right_side")
        self.assertEqual(vs.right_forward, rf, "different value: right_side")
        self.assertEqual(vs.sum_all, lf+ls+rs+rf, "different value: sum_all")
        self.assertEqual(vs.sum_forward, lf+rf, "different value: sum_forward")

    def test_node_exist(self):
        nodes = rosnode.get_node_names()
        self.assertIn('/lightsensors', nodes, "node does not exist")

    def test_get_value(self):
        rospy.set_param('lightsensors_freq', 10)
        time.sleep(2)
        with open("/dev/rtlightsensor0","w") as f:
            f.write("1 1 1 1\n")
            # f.write("-1 0 123 4321\n")
        time.sleep(3)
        self.assertFalse(self.count == 0,"cannot subscribe the topic")
        self.check_values(1,1,1,1)

    def test_change_parameter(self):
        rospy.set_param('lightsensors_freq',1)
        time.sleep(2)
        c_prev = self.count
        time.sleep(3)
        self.assertTrue(self.count < c_prev + 4,"freq does not change")
        self.assertFalse(self.count == c_prev,"subscriber is stopped")

if __name__ == '__main__':
    time.sleep(3)
    rospy.init_node('travis_test_lightsensors')
    rostest.rosrun('pimouse_ros','travis_test_lightsensors', LightsensorTest)

<commit_msg>LightSenserTest 7.5<commit_after>#! /usr/bin/env python
#encoding: utf8
import rospy, unittest, rostest
import rosnode
import time
from pimouse_ros.msg import LightSensorValues 

class LightsensorTest(unittest.TestCase):
    def setUp(self):
        self.count = 0
        rospy.Subscriber('/lightsensors', LightSensorValues, self.callback)
        self.values = LightSensorValues()

    def callback(self,data):
        self.count += 1
        self.values = data
    
    def check_values(self,lf,ls,rs,rf):
        vs = self.values
        self.assertEqual(vs.left_forward, lf, "different value: left_forward")
        self.assertEqual(vs.left_side, ls, "different value: left_side")
        self.assertEqual(vs.right_side, rs, "different value: right_side")
        self.assertEqual(vs.right_forward, rf, "different value: right_side")
        self.assertEqual(vs.sum_all, lf+ls+rs+rf, "different value: sum_all")
        self.assertEqual(vs.sum_forward, lf+rf, "different value: sum_forward")

    def test_node_exist(self):
        nodes = rosnode.get_node_names()
        self.assertIn('/lightsensors', nodes, "node does not exist")

    def test_get_value(self):
        rospy.set_param('lightsensors_freq', 10)
        time.sleep(2)
        with open("/dev/rtlightsensor0","w") as f:
            f.write("-1 0 123 4321\n")
        time.sleep(3)
        self.assertFalse(self.count == 0,"cannot subscribe the topic")
        self.check_values(4321,123,0,-1)

    def test_change_parameter(self):
        rospy.set_param('lightsensors_freq',1)
        time.sleep(2)
        c_prev = self.count
        time.sleep(3)
        self.assertTrue(self.count < c_prev + 4,"freq does not change")
        self.assertFalse(self.count == c_prev,"subscriber is stopped")

if __name__ == '__main__':
    time.sleep(3)
    rospy.init_node('travis_test_lightsensors')
    rostest.rosrun('pimouse_ros','travis_test_lightsensors', LightsensorTest)


{'fraction_non_alphanumeric': 0.12131315721979995, 'fraction_numerical': 0.016670941266991535, 'mean_word_length': 3.1980624327233587, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2954855', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1271, 'n_words': 249}