def test_add(self, mock_validation):
        """
        Tests that add calls for validation and adds to total_count.
        """
        capture = DataCapture()

        # adding a number should validate it
        capture.add(1)
        mock_validation.assert_called()

        # and increment the total count and individual count
        self.assertEqual(capture.total_count, 1)
        self.assertEqual(capture.numbers[1]['count'], 1)

        # and continue to increment
        capture.add(1)
        self.assertEqual(capture.total_count, 2)
        self.assertEqual(capture.numbers[1]['count'], 2)

        # Adding a different number should increment for that number only
        # and also for the total count.
        capture.add(2)
        self.assertEqual(capture.total_count, 3)
        self.assertEqual(capture.numbers[1]['count'], 2)
        self.assertEqual(capture.numbers[2]['count'], 1)

        with self.assertRaisesRegex(
                ValueError, 'This method only accepts values up to 999.'):
            capture.add(1000)
    def test_calculations(self, mock_validation):
        """
        Tests calculations for DataCapture.
        """
        capture = DataCapture()
        for number in (3, 9, 3, 4, 6):
            capture.add(number)
        mock_validation.reset_mock()
        stats = capture.build_stats()

        # test with ordinary values
        self.assertEqual(stats.less(4), 2)
        self.assertEqual(stats.between(3, 6), 4)
        # between with number below our lowest count
        self.assertEqual(stats.between(2, 6), 4)
        # between with intermediate number that has no count
        self.assertEqual(stats.between(2, 8), 4)
        # between with number above our highest count
        self.assertEqual(stats.between(4, 10), 3)
        self.assertEqual(stats.greater(4), 2)

        # test with greater than max value
        self.assertEqual(stats.less(1000), 5)
        self.assertEqual(stats.greater(1000), 0)
        self.assertEqual(stats.between(4, 1000), 3)

        # make sure validation was called for each passed number
        self.assertEqual(mock_validation.call_count, 15)
class TestFunctions(unittest.TestCase):

  def setUp(self):
    self.capture = DataCapture(TEST_FILE)
  
  def testSetAndGet(self):
    a = range(10)
    b = range(20)
    self.capture.setData([a,b])
    x, y = self.capture.getData()
    self.assertTrue(a == x)
    self.assertTrue(b == y)
Beispiel #4
0
def main():

    rospy.init_node('data_capture_node')

    storage_path = rospy.get_param('~storage_path', default_storage_path)
    DataCapture(storage_path)

    rospy.spin()
Beispiel #5
0
def store_data():
	global dataCapture
	threshold = request.form['threshold']
	try:
		if dataCapture is None:
			dataCapture = DataCapture(threshold, getFramBytes, generateInferenceResultMessage)
		dataCapture.setThreshold(threshold)
		dataCapture.toggleEnabled()
	except ValueError as ve:
		print(ve)
	return jsonify({'threshold': dataCapture.getThreshold(), 'enabled': dataCapture.isEnabled()})
Beispiel #6
0
def test_add_values(stats):
    capture = DataCapture(stats)
    assert stats.count == 0
    capture.add(3)
    assert stats.count == 1
    capture.add(3)
    assert stats.count == 2
 def setUp(self):
   self.capture = DataCapture(TEST_FILE)
Beispiel #8
0
def getCapture(filename):
  dc = DataCapture(filename)
  return dc.getData()
Beispiel #9
0
def capture(stats):
    return DataCapture()