Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Add tests for reading file functions
Browse files Browse the repository at this point in the history
  • Loading branch information
forslund committed Mar 9, 2020
1 parent c051d7a commit 2589784
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/unittests/util/muppets.dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
muppet = miss piggy
fraggle = gobo
19 changes: 17 additions & 2 deletions test/unittests/util/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

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 = {
Expand Down Expand Up @@ -85,6 +85,21 @@ def create_cache_files(cache_dir):
return huxley_path, aldous_path


def 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():
Expand Down
5 changes: 5 additions & 0 deletions test/unittests/util/unstripped_lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Once upon a time
there was a great Dragon
It was red and cute

The end

0 comments on commit 2589784

Please sign in to comment.