Пример #1
0
    def test_init(self, mock_can_connect):
        """Can initialize instance of FloodLight class"""

        # Mock the OPC can_connect function
        mock_can_connect.return_value = True
        # Check it is the right object
        self.assertIsInstance(floodlight.FloodLight(config),
                              floodlight.FloodLight)
Пример #2
0
 def test_init_error(self):
     """Catches error with Fadecandy connection"""
     try:
         floodlight.FloodLight(config)
     except Exception as e:
         self.assertEqual(
             'Could not connect to Fadecandy server at %s' %
             config['fadecandy']['server'], str(e))
Пример #3
0
    def test_get_report_count_error(self, mock_can_connect):
        """Can catch errors with CogniCity endpoint"""

        # Mock the OPC can_connect function
        mock_can_connect.return_value = True
        # Set the config endpoint to junk
        config['cognicity']['reports_endpoint'] = 'http://localhost'
        # Get the error count
        count = floodlight.FloodLight(config)._get_report_count()
        self.assertEqual(count, -1)
Пример #4
0
def main():
    """Run floodlight"""
    # Create floodlight instance
    fl = floodlight.FloodLight(config)
    # Start process, catching KeyboardInterrupts
    try:
        fl.start()
    except KeyboardInterrupt:
        logger.info("Exit called by user (KeyboardInterrupt), will now exit.")
        sys.exit(0)
Пример #5
0
    def test_get_report_count(self, mock_can_connect, mock_requests_get):
        """Returns count of GeoJSON object"""

        # Mock the OPC can_connect function
        mock_can_connect.return_value = True
        # Mock the requests object
        mock_requests_get.return_value = MagicMock(
            status_code=200,
            json=lambda: json.loads(
                json.dumps({'result': {
                    'features': [0, 1, 2]
                }})))
        # Initialize the class
        count = floodlight.FloodLight(config)._get_report_count()
        # Test
        self.assertEqual(count, 3)
Пример #6
0
    def test_send_sequence(self, mock_can_connect, mock_put_pixels,
                           mock_time_sleep):
        """Test send sequence method"""

        # Mock the OPC can_connect function
        mock_can_connect.return_value = True

        # Execute the send sequence method
        floodlight.FloodLight(config)._send_sequence([{
            'pattern': [(1, 2, 3)],
            'timing': 10
        }])

        # Test that put pixels called with expected value
        mock_put_pixels.assert_called_with([(1, 2, 3)])

        # Check that sleep value called as expected
        mock_time_sleep.assert_called_with(10)
Пример #7
0
    def test_start(self, mock_get_report_count, mock_send_sequence,
                   mock_can_connect, mock_put_pixels, mock_time_sleep):
        """Test send sequence method"""

        mock_get_report_count.return_value = 2

        # Mock the OPC can_connect function
        mock_can_connect.return_value = True

        # Execute the send sequence method
        try:
            floodlight.FloodLight(config).start()
        except InterruptedError:

            # Construct the expected sequence
            sequence = _sequence.Sequence(config).build(0, 2)

            # Test that put pixels called with expected value
            mock_send_sequence.assert_called_with(sequence)

            # Check that sleep value called as expected
            mock_time_sleep.assert_called_with(60)
Пример #8
0
import sys
import os

sys.path.insert(
    0, os.path.abspath(os.path.join(os.path.dirname(__file__),
                                    '../floodlight')))

import _config
import _sequence
import floodlight

config = _config.load_config('config.json')
fl = floodlight.FloodLight(config)
sq = _sequence.Sequence(config)

sequence = sq.build(8, 12)
fl._send_sequence(sequence)