def test_float_in_file(self): try: tf = tempfile.NamedTemporaryFile(dir='.', delete=False) tf.write(b'4\n2\n1.0\n3\n') tf.close() with patch('sys.argv', ['testprog', tf.name, 'median', 'gt', '2']): with self.assertRaises(ValueError): koodauskoe_main() finally: os.remove(tf.name)
def test_with_string_value_in_file(self): try: tf = tempfile.NamedTemporaryFile(dir='.', delete=False) tf.write(b'5\nX\n3\n') tf.close() with patch('sys.argv', ['testprog', tf.name, 'sum', 'lt', '50']): with self.assertRaises(ValueError): koodauskoe_main() finally: os.remove(tf.name)
def test_case1(self): try: tf = tempfile.NamedTemporaryFile(dir='.', delete=False) tf.write(b'4\n2\n1\n3\n') tf.close() with patch('sys.argv', ['testprog', tf.name, 'sum', 'lt', '50']): with captured_output() as out: koodauskoe_main() output = out.getvalue().strip() self.assertEqual(output, 'Summa on: 10\n10 on pienempi kuin 50') finally: os.remove(tf.name)
def test_case2(self): try: tf = tempfile.NamedTemporaryFile(dir='.', delete=False) tf.write(b'4\n2\n1\n3\n') tf.close() with patch('sys.argv', ['testprog', tf.name, 'avg', 'eq', '2.5']): with captured_output() as out: koodauskoe_main() output = out.getvalue().strip() self.assertEqual( output, 'Keskiarvo on: 2.5\n2.5 on yhtä suuri kuin 2.5') finally: os.remove(tf.name)
def test_case3(self): try: tf = tempfile.NamedTemporaryFile(dir='.', delete=False) tf.write(b'4\n2\n1\n3\n') tf.close() with patch('sys.argv', ['testprog', tf.name, 'median', 'gt', '2']): with captured_output() as out: koodauskoe_main() output = out.getvalue().strip() self.assertEqual( output, 'Mediaani on: 2 ja 3\n2 ei ole suurempi kuin 2\n3 on suurempi kuin 2' ) finally: os.remove(tf.name)
def test_all_sum(self): with self.assertRaises(ValueError): koodauskoe_main()
def test_illegal_2nd_arg(self): with self.assertRaises(ValueError): koodauskoe_main()
def test_illegal_2nd_optional_argument(self): with self.assertRaises(ValueError): koodauskoe_main()
def test_missing_2nd_optional_argument(self): with self.assertRaises(IndexError): koodauskoe_main()
def test_1_arg(self): with self.assertRaises(IndexError): koodauskoe_main()