test_calc.py 777 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import unittest
  2. from src.calc import Parser
  3. class TestParser(Parser):
  4. def __init__(self, input_buffer, **kwargs):
  5. Parser.__init__(self, **kwargs)
  6. self.input_buffer = []
  7. self.input_position = 0
  8. map(self.append, input_buffer)
  9. def append(self, input):
  10. self.input_buffer.append(input + '\n')
  11. def read(self, nbytes):
  12. buffer = ''
  13. try:
  14. buffer = self.input_buffer[self.input_position]
  15. except IndexError:
  16. return ''
  17. self.input_position += 1
  18. return buffer
  19. class TestCalc(unittest.TestCase):
  20. def setUp(self):
  21. pass
  22. def tearDown(self):
  23. pass
  24. def test_constructor(self):
  25. assert TestParser(['1+4'], keepfiles=1).run() == 5.0