# Path: greenpithumb/clock.py
# class Clock(object):
# class LocalClock(Clock):
# class Timer(object):
#     def wait(self, wait_time_seconds):
#     def now(self):
#     def now(self):
#     def __init__(self, clock, duration):
#     def set_remaining(self, time_remaining):
#     def expired(self):
#     def reset(self):
# 
# Path: greenpithumb/pump.py
# _PUMP_RATE_ML_PER_SEC = 4300.0 / 60.0
# DEFAULT_PUMP_AMOUNT = 200
# class Pump(object):
# class PumpManager(object):
# class PumpScheduler(object):
#     def __init__(self, pi_io, clock, pump_pin):
#     def pump_water(self, amount_ml):
#     def __init__(self, pump, pump_scheduler, moisture_threshold, pump_amount,
#                  timer):
#     def pump_if_needed(self, moisture):
#     def _should_pump(self, moisture):
#     def __init__(self, local_clock, sleep_windows):
#     def is_running_pump_allowed(self):


import datetime
import unittest
import mock
import pytz
from greenpithumb import clock
from greenpithumb import pump




class PumpTest(unittest.TestCase):

    def setUp(self):
        self.mock_pi_io = mock.Mock()
        self.mock_clock = mock.Mock(spec=clock.Clock)

    def test_pump_4_3_liters(self):
        pump.Pump(
            self.mock_pi_io, self.mock_clock, pump_pin=6).pump_water(4300.0)
        # Pump should call wait() exactly once.
        self.assertEqual(1, len(self.mock_clock.wait.call_args_list))
        wait_time_actual = self.mock_clock.wait.call_args[0][0]
        # At 4.3 L/min, pump should run for exactly 60 seconds.
        wait_time_expected = 60.0
        # There is loss of precision with floating point arithmetic, so we
        # verify that the values are equal to several significant digits.
        self.assertAlmostEqual(wait_time_expected, wait_time_actual)
        # Verify the signal gets sent to turn the pump pin on, then off.
        self.mock_pi_io.turn_pin_on.assert_called_once_with(6)
        self.mock_pi_io.turn_pin_off.assert_called_once_with(6)

    def test_pump_2_15_liters(self):
        pump.Pump(
            self.mock_pi_io, self.mock_clock, pump_pin=6).pump_water(2150.0)
        # Pump should call wait() exactly once.
        self.assertEqual(1, len(self.mock_clock.wait.call_args_list))

# Path: greenpithumb/clock.py
# class Clock(object):
# class LocalClock(Clock):
# class Timer(object):
#     def wait(self, wait_time_seconds):
#     def now(self):
#     def now(self):
#     def __init__(self, clock, duration):
#     def set_remaining(self, time_remaining):
#     def expired(self):
#     def reset(self):
# 
# Path: greenpithumb/pump.py
# _PUMP_RATE_ML_PER_SEC = 4300.0 / 60.0
# DEFAULT_PUMP_AMOUNT = 200
# class Pump(object):
# class PumpManager(object):
# class PumpScheduler(object):
#     def __init__(self, pi_io, clock, pump_pin):
#     def pump_water(self, amount_ml):
#     def __init__(self, pump, pump_scheduler, moisture_threshold, pump_amount,
#                  timer):
#     def pump_if_needed(self, moisture):
#     def _should_pump(self, moisture):
#     def __init__(self, local_clock, sleep_windows):
#     def is_running_pump_allowed(self):


# Path: tests/test_pump.py
import datetime
import unittest
import mock
import pytz
from greenpithumb import clock
from greenpithumb import pump





class PumpTest(unittest.TestCase):

    def setUp(self):
        self.mock_pi_io = mock.Mock()
        self.mock_clock = mock.Mock(spec=clock.Clock)

    def test_pump_4_3_liters(self):
        pump.Pump(
            self.mock_pi_io, self.mock_clock, pump_pin=6).pump_water(4300.0)
        # Pump should call wait() exactly once.
        self.assertEqual(1, len(self.mock_clock.wait.call_args_list))
        wait_time_actual = self.mock_clock.wait.call_args[0][0]
        # At 4.3 L/min, pump should run for exactly 60 seconds.
        wait_time_expected = 60.0
        # There is loss of precision with floating point arithmetic, so we
        # verify that the values are equal to several significant digits.
        self.assertAlmostEqual(wait_time_expected, wait_time_actual)
        # Verify the signal gets sent to turn the pump pin on, then off.
        self.mock_pi_io.turn_pin_on.assert_called_once_with(6)
        self.mock_pi_io.turn_pin_off.assert_called_once_with(6)

    def test_pump_2_15_liters(self):
        pump.Pump(
            self.mock_pi_io, self.mock_clock, pump_pin=6).pump_water(2150.0)
        # Pump should call wait() exactly once.
        self.assertEqual(1, len(self.mock_clock.wait.call_args_list))

        wait_time_actual = self.mock_clock.wait.call_args[0][0]