Example #1
0
 def test_check_config_file_passes(self):
     # Arrange
     file_name = os.path.join(os.getcwd(), 'valid.json')
     config_json = \
         '{' \
         '   "laptimer": {' \
         '       "url": "ws://127.0.0.1:8080/ws"' \
         '   },' \
         '   "sensors": [{' \
         '       "name": "Start & finish",' \
         '       "url": "ws://127.0.0.1:8888/ws",' \
         '       "location": "START_FINISH",' \
         '       "hardware": "RPI_REV2",' \
         '       "pinLedApp": 13,' \
         '       "pinLedLap": 16,' \
         '       "pinLedEvent": 18,' \
         '       "pinEvent": 22' \
         '    }]' \
         '}'
     file_name = os.path.join(os.getcwd(), file_name)
     if os.path.isfile(file_name):
         os.remove(file_name)
     with open(file_name, 'w') as config_file:
         config_file.write(config_json)
     # Act
     cfg = check.check_config_file(file_name)
     # Assert
     laptimer = cfg['laptimer']
     url = laptimer['url']
     self.assertEqual('ws://127.0.0.1:8080/ws', url)
     # Cleanup
     os.remove(file_name)
Example #2
0
 def test_check_config_file_passes(self):
     # Arrange
     file_name = os.path.join(os.getcwd(), 'valid.json')
     config_json = \
         '{' \
         '   "laptimer": {' \
         '       "url": "ws://127.0.0.1:8080/ws"' \
         '   },' \
         '   "sensors": [{' \
         '       "name": "Start & finish",' \
         '       "url": "ws://127.0.0.1:8888/ws",' \
         '       "location": "START_FINISH",' \
         '       "hardware": "RPI_REV2",' \
         '       "pinLedApp": 13,' \
         '       "pinLedLap": 16,' \
         '       "pinLedEvent": 18,' \
         '       "pinEvent": 22' \
         '    }]' \
         '}'
     file_name = os.path.join(os.getcwd(), file_name)
     if os.path.isfile(file_name):
         os.remove(file_name)
     with open(file_name, 'w') as config_file:
         config_file.write(config_json)
     # Act
     cfg = check.check_config_file(file_name)
     # Assert
     laptimer = cfg['laptimer']
     url = laptimer['url']
     self.assertEqual('ws://127.0.0.1:8080/ws', url)
     # Cleanup
     os.remove(file_name)
Example #3
0
 def test_check_config_file_raises_exception_when_file_is_invalid_json(self):
     # Arrange
     file_name = os.path.join(os.getcwd(), 'bogus.json')
     if os.path.isfile(file_name):
         os.remove(file_name)
     with open(file_name, 'w') as config_file:
         config_file.write('bogus')
     # Act
     with self.assertRaises(Exception) as context:
         check.check_config_file(file_name)
     # Assert
     msg = "Configuration file '{}' does not seem to be proper JSON (No " \
           "JSON object could be decoded)".format(file_name)
     self.assertEqual(context.exception.message, msg)
     # Cleanup
     os.remove(file_name)
Example #4
0
 def test_check_config_file_raises_exception_when_file_is_invalid_json(
         self):
     # Arrange
     file_name = os.path.join(os.getcwd(), 'bogus.json')
     if os.path.isfile(file_name):
         os.remove(file_name)
     with open(file_name, 'w') as config_file:
         config_file.write('bogus')
     # Act
     with self.assertRaises(Exception) as context:
         check.check_config_file(file_name)
     # Assert
     msg = "Configuration file '{}' does not seem to be proper JSON (No " \
           "JSON object could be decoded)".format(file_name)
     self.assertEqual(context.exception.message, msg)
     # Cleanup
     os.remove(file_name)
Example #5
0
    def __init__(self, session, config_file):
        self.session = session
        self.config = check.check_config_file(config_file)
        self.config_file = config_file

        log.msg("Pi-time API v{} ready".format(pi_time.API_VERSION))