Skip to content

Commit

Permalink
Merge pull request #3 from frnhr/patrik_develop
Browse files Browse the repository at this point in the history
moar unittests
  • Loading branch information
pkukic authored Apr 24, 2019
2 parents d14a38b + 00f49d5 commit c769343
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
10 changes: 5 additions & 5 deletions void/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ def main():
ra, dec, time_unix = selector.line_to_point(line)
line_points.append([ra, dec, time_unix])
log.info(f'processing {line}')

paths = selector.linestr_points_intersection(line_points)
for path in paths:
sys.stdout.write(path)
except KeyboardInterrupt:
log.debug('SIGINT')

paths = selector.linestr_points_intersection(line_points)
for path in paths:
sys.stdout.write(path)


if __name__ == '__main__':
if __name__ == '__main__': # pragma no cover
main()
2 changes: 2 additions & 0 deletions void/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ def test_configure_log(self, p_logging):
def test_configure_log_unknown_cerbosity(self, *_):
with self.assertRaises(docopt.DocoptExit):
common.configure_log('321')

# TODO test for Settings
55 changes: 54 additions & 1 deletion void/tests/test_selector.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import unittest
from unittest import mock

from void import common
from void.settings import settings
from void.writer import Writer
from void.selector import Selector
from void.selector import Selector, main

# Test polygons
P_1 = [[2, 2], [-2, 2], [-2, -2], [2, -2]]
Expand Down Expand Up @@ -67,6 +68,21 @@ def test_line_to_point(self):
output[2] = round(output[2], 3)
self.assertEqual(expected, output)

def test_line_to_point_no_mins(self):
line = (
"2019 04 24 14 "
"09.0726 -06.407"
" 105.5 20.5"
" 3.90 345.4"
" 303 +20 +36"
" 0.72 133 -64 M"
)
expected = [9.0726, -6.407, 1_556_114_400]
with Selector() as selector:
output = list(selector.line_to_point(line))
output[2] = round(output[2], 3)
self.assertEqual(expected, output)

def test_linestr_horiz(self):
line_points = [[0, 0, T_1], [5, 0, T_1]]
expected = ['P_1', 'P_2']
Expand Down Expand Up @@ -101,3 +117,40 @@ def test_vert_angle(self):
with Selector() as selector:
output = selector.linestr_points_intersection(line_points)
self.assertEqual(expected, output)


class MainTests(unittest.TestCase):

@mock.patch('void.selector.common')
@mock.patch('void.selector.docopt')
@mock.patch('void.selector.sys')
@mock.patch('void.selector.Selector')
def test_lines(self, p_selector_cls, p_sys, *_):
m_lines = ['line 1', '', 'line 3']
selector = p_selector_cls.return_value
m_paths = ('path 1', 'path 2',)
m_line_points = [('ra1', 'de1', 't1'), ('ra2', 'de2', 't2')]
p_sys.stdin = m_lines
selector.linestr_points_intersection.return_value = m_paths
selector.line_to_point.side_effect = m_line_points
main()
self.assertEqual(
[mock.call('line 1'), mock.call('line 3')],
selector.line_to_point.call_args_list)
selector.linestr_points_intersection.assert_called_once()
self.assertEqual(
[mock.call('path 1'), mock.call('path 2')],
p_sys.stdout.write.call_args_list)

@mock.patch('void.selector.common')
@mock.patch('void.selector.docopt')
@mock.patch('void.selector.sys')
@mock.patch('void.selector.log')
@mock.patch('void.selector.Selector')
def test_sigint(self, p_selector_cls, p_log, p_sys, *_):
m_lines = ['line 1',]
selector = p_selector_cls.return_value
p_sys.stdin = m_lines
selector.line_to_point.side_effect = KeyboardInterrupt()
main()
p_log.debug.assert_called_with('SIGINT')

0 comments on commit c769343

Please sign in to comment.