Skip to content

Commit

Permalink
More testing on utils
Browse files Browse the repository at this point in the history
  • Loading branch information
YuukanOO committed Dec 13, 2018
1 parent 2eb5100 commit 3a9be57
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from sure import expect
from pytlas.utils import find_match, keep_one
from unittest.mock import patch, mock_open
from pytlas.utils import find_match, keep_one, read_file

class TestFindMatch:

Expand Down Expand Up @@ -29,4 +30,17 @@ def test_it_returns_the_given_value_if_not_an_array(self):
def test_it_returns_one_of_given_value_if_its_an_array(self):
values = ['a value', 'another value', 'something more']

expect(keep_one(values)).to.be.within(values)
expect(keep_one(values)).to.be.within(values)

class TestReadFile:

def test_it_should_raise_an_exception_when_errors_not_ignored(self):
expect(lambda: read_file('something')).to.throw(Exception)

def test_it_should_not_raise_exception_when_errors_ignored(self):
expect(read_file('something', ignore_errors=True)).to.be.none

def test_it_should_read_the_file_correctly(self):
with patch('builtins.open', mock_open(read_data='some content')):
expect(read_file('somepath')).to.equal('some content')

0 comments on commit 3a9be57

Please sign in to comment.