Skip to content

Commit

Permalink
tests:asciimap: increase coverage
Browse files Browse the repository at this point in the history
Exercise the "validate shape" function a little by passing some invalid
command line options in.
  • Loading branch information
rjw57 committed Oct 23, 2014
1 parent 1ea0f17 commit defc3f5
Showing 1 changed file with 69 additions and 1 deletion.
70 changes: 69 additions & 1 deletion tests/testasciimap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
except ImportError:
from mock import patch, call

from nose.tools import raises

from .util import DownloadedDatasetTestCase

import ruaumoko.asciiart as raa
Expand Down Expand Up @@ -43,14 +45,80 @@ def test_simple_output(self):

# Call the ascii map generator main function
with argv_patch, stdout_write_patch as mock_write:
raa.main()
rv = raa.main()
captured_output = ''.join(args[0] for args, kwargs in mock_write.call_args_list)
captured_output = captured_output.splitlines()

# Check success
self.assertEqual(rv, 0)

# Check that the right number of lines were output
self.assertEqual(len(captured_output), len(expected_output_60_20))

# Check each line
for co_line, eo_line in zip(captured_output, expected_output_60_20):
self.assertEqual(co_line, eo_line)

@raises(ValueError)
def test_incorrect_tile_size(self):
argv_patch = patch('sys.argv', [
'ruaumoko-ascii-map', '-s', '60x20', '--tile-shape', '30x10', self.dataset_path])
with argv_patch:
rv = raa.main()
self.assertNotEqual(rv, 0)

def test_invalid_tile_size_negative(self):
argv_patch = patch('sys.argv', [
'ruaumoko-ascii-map', '-s', '60x20', '--tile-shape', '20x-10', self.dataset_path])
with argv_patch:
rv = raa.main()
self.assertNotEqual(rv, 0)

def test_invalid_tile_size_non_int(self):
argv_patch = patch('sys.argv', [
'ruaumoko-ascii-map', '-s', '60x20', '--tile-shape', 'twentyx10', self.dataset_path])
with argv_patch:
rv = raa.main()
self.assertNotEqual(rv, 0)

def test_invalid_tile_size_too_few(self):
argv_patch = patch('sys.argv', [
'ruaumoko-ascii-map', '-s', '60x20', '--tile-shape', '20', self.dataset_path])
with argv_patch:
rv = raa.main()
self.assertNotEqual(rv, 0)

def test_invalid_tile_size_too_many(self):
argv_patch = patch('sys.argv', [
'ruaumoko-ascii-map', '-s', '60x20', '--tile-shape', '20x10x1', self.dataset_path])
with argv_patch:
rv = raa.main()
self.assertNotEqual(rv, 0)

def test_invalid_output_size_negative(self):
argv_patch = patch('sys.argv', [
'ruaumoko-ascii-map', '-s', '60x-20', '--tile-shape', '20x10', self.dataset_path])
with argv_patch:
rv = raa.main()
self.assertNotEqual(rv, 0)

def test_invalid_output_size_non_int(self):
argv_patch = patch('sys.argv', [
'ruaumoko-ascii-map', '-s', '60xtwenty', '--tile-shape', '20x10', self.dataset_path])
with argv_patch:
rv = raa.main()
self.assertNotEqual(rv, 0)

def test_invalid_output_size_too_few(self):
argv_patch = patch('sys.argv', [
'ruaumoko-ascii-map', '-s', '60', '--tile-shape', '20x10', self.dataset_path])
with argv_patch:
rv = raa.main()
self.assertNotEqual(rv, 0)

def test_invalid_output_size_too_many(self):
argv_patch = patch('sys.argv', [
'ruaumoko-ascii-map', '-s', '60x20x1', '--tile-shape', '20x10', self.dataset_path])
with argv_patch:
rv = raa.main()
self.assertNotEqual(rv, 0)

0 comments on commit defc3f5

Please sign in to comment.