<commit_before>"""Unit tests for the robot module."""

import unittest

from mock import MagicMock

import robot


class RobotTests(unittest.TestCase):
	"""Unit tests for the Robot class."""

	def setUp(self):
		robot.mount = MagicMock()
		robot.sensor = MagicMock()
		self.r = robot.Robot(driver_module='tests.gopigo_stub')

	def test_init(self):
		"""Verify robot's attributes."""

		self.assertEqual(self.r.state, None)

	def test_run(self):
		"""Verify run() is delegated to the robot's state."""

		mock_state = MagicMock()
		mock_state.run.return_value = True

		with self.assertRaises(AttributeError):
			self.r.run()

		self.r.state = mock_state
		self.assertTrue(self.r.run())
		mock_state.run.assert_called_once_with()<commit_msg>Test for sense().<commit_after>"""Unit tests for the robot module."""

import unittest

from mock import MagicMock

import robot


class RobotTests(unittest.TestCase):
	"""Unit tests for the Robot class."""

	def setUp(self):
		self.mock_sensor = MagicMock()
		self.r = robot.Robot(driver_module='tests.gopigo_stub')
		self.r.sensor = self.mock_sensor

	def test_init(self):
		"""Verify robot's attributes."""

		self.assertEqual(self.r.state, None)
		self.assertEqual(self.r.sensor, self.mock_sensor)

	def test_run(self):
		"""Verify run() is delegated to the robot's state."""

		mock_state = MagicMock()
		mock_state.run.return_value = True

		with self.assertRaises(AttributeError):
			self.r.run()

		self.r.state = mock_state
		self.assertTrue(self.r.run())
		mock_state.run.assert_called_once_with()

	def test_sense(self):
		"""Verify sense() is delegated to the sensor."""

		self.mock_sensor.sense.return_value = 50
		self.assertEqual(self.r.sense(foo='bar'), 50)
		self.mock_sensor.sense.assert_called_once_with(foo='bar')

	def test_stop(self):
		"""Verify stop() is delegated to the driver."""

		self.r.stop()
		self.assertEqual(self.r.driver.calls[-1], 'stop()')
{'fraction_non_alphanumeric': 0.14233576642335766, 'fraction_numerical': 0.0026068821689259644, 'mean_word_length': 4.627565982404692, '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': '7023316', 'n_tokens_mistral': 705, 'n_tokens_neox': 647, 'n_words': 145}