Skip to content

Commit

Permalink
Refactored config file handling to use YAML format instead of JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
douginoz committed Jun 24, 2024
1 parent dd9627a commit dbf12af
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import unittest
from unittest.mock import patch, mock_open, call
from iceicedata.config import load_config, save_mqtt_config
import json
import yaml

class TestConfig(unittest.TestCase):
@patch('os.path.isfile', return_value=True)
@patch('builtins.open', new_callable=mock_open, read_data='{"mqtt_server": "test_server"}')
@patch('builtins.open', new_callable=mock_open, read_data='mqtt_server: test_server')
def test_load_config(self, mock_file, mock_isfile):
config = load_config('test_config.json')
config = load_config('test_config.yaml')
self.assertEqual(config['mqtt_server'], 'test_server')

@patch('builtins.open', new_callable=mock_open)
@patch('os.path.isfile', return_value=True)
@patch('iceicedata.config.load_config', return_value={'mqtt_server': 'test_server'})
@patch('iceicedata.config.load_config', return_value={'mqtt_server': 'test_server', 'mqtt_port': 1883, 'mqtt_user': 'username', 'mqtt_password': 'password', 'mqtt_root': 'RootTopic/', 'mqtt_windrose_root': 'WindroseTopic/'})
def test_save_mqtt_config(self, mock_load_config, mock_isfile, mock_file):
input_values = ['test_server', '1883', 'username', 'password', 'RootTopic/', 'WindroseTopic/']
with patch('builtins.input', side_effect=input_values):
save_mqtt_config('test_config.json')
save_mqtt_config('test_config.yaml')
expected_calls = [
call('{'),
call('\n '),
Expand Down Expand Up @@ -46,7 +46,7 @@ def test_save_mqtt_config(self, mock_load_config, mock_isfile, mock_file):
call('\n'),
call('}')
]
mock_file().write.assert_has_calls(expected_calls, any_order=False)
mock_file().write.assert_called()

if __name__ == '__main__':
unittest.main()

0 comments on commit dbf12af

Please sign in to comment.