Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
 def test_all_sum(self):
     with self.assertRaises(ValueError):
         koodauskoe_main()
Пример #7
0
 def test_illegal_2nd_arg(self):
     with self.assertRaises(ValueError):
         koodauskoe_main()
Пример #8
0
 def test_illegal_2nd_optional_argument(self):
     with self.assertRaises(ValueError):
         koodauskoe_main()
Пример #9
0
 def test_missing_2nd_optional_argument(self):
     with self.assertRaises(IndexError):
         koodauskoe_main()
Пример #10
0
 def test_1_arg(self):
     with self.assertRaises(IndexError):
         koodauskoe_main()