Add tests for reading file functions

pull/2496/head
Åke Forslund 2020-03-09 13:54:57 +01:00
parent 76ff53a615
commit 0d79af8ce2
3 changed files with 24 additions and 2 deletions

View File

@ -0,0 +1,2 @@
muppet = miss piggy
fraggle = gobo

View File

@ -6,8 +6,8 @@ from unittest import TestCase, mock
from mycroft import MYCROFT_ROOT_PATH
from mycroft.util import (resolve_resource_file, curate_cache,
get_cache_directory, play_ogg, play_mp3, play_wav,
play_audio_file,
get_cache_directory, read_stripped_lines, read_dict,
play_ogg, play_mp3, play_wav, play_audio_file,
camel_case_split, get_http, remove_last_slash)
test_config = {
@ -85,6 +85,21 @@ def create_cache_files(cache_dir):
return huxley_path, aldous_path
class TestReadFiles(TestCase):
base = dirname(__file__)
def test_read_stripped_lines(self):
expected = ['Once upon a time', 'there was a great Dragon',
'It was red and cute', 'The end']
unstripped_path = join(TestReadFiles.base, 'unstripped_lines.txt')
self.assertEqual(read_stripped_lines(unstripped_path), expected)
def test_read_dict(self):
expected = {'fraggle': 'gobo', 'muppet': 'miss piggy'}
dict_path = join(TestReadFiles.base, 'muppets.dict')
self.assertEqual(read_dict(dict_path), expected)
@mock.patch('mycroft.configuration.Configuration')
class TestCache(TestCase):
def tearDownClass():

View File

@ -0,0 +1,5 @@
Once upon a time
there was a great Dragon
It was red and cute
The end