Ejemplo n.º 1
0
def test_entry_conditions_invalid():
    with pytest.raises(ValueError) as excinfo:
        locke = Locke(5)
        locke.move_boats_through(15)

    assert str(excinfo.value) == "{} accepts {} boats max."\
                                 .format(locke.size, locke.limit)
Ejemplo n.º 2
0
def test_locke_typeerrors_on_str_inputs():
    """given inputs other than positive ints or 0
    the locke sends inputerror on initialization"""
    locke1 = Locke(5)
    boats = 'hello'
    with pytest.raises(TypeError):
        with locke1:
            locke1.move_boats_through(boats)
Ejemplo n.º 3
0
def test_locke_errors_on_bad_inputs(bad_input):
    """given inputs other than positive ints or 0
    the locke sends inputerror on initialization"""
    locke1 = Locke(5)
    boats = bad_input
    with pytest.raises(ValueError):
        with locke1:
            locke1.move_boats_through(boats)
Ejemplo n.º 4
0
def test_move_boats_through(capsys):
    small_locke = Locke(5)

    small_locke.move_boats_through(5)

    captured = capsys.readouterr()
    assert captured.out == "Opening the doors.\n"\
                           "Closing the doors.\n"
Ejemplo n.º 5
0
def test_locke_rejects_boats_count_over_limit():
    """given a lock established with a boat limit of 5
    when more than limit of boats are input
    the locke raises value error exception"""
    locke1 = Locke(5)
    boats = 6
    with pytest.raises(ValueError):
        with locke1:
            locke1.move_boats_through(boats)
Ejemplo n.º 6
0
	def test_move_boats_less_than_capacity(self):
		number_boats = 8
		capacity = 10
		locke = Locke(capacity)
		expected_output = "*********  Moved 8 boats through the Locke successfully  *********"
		capturedOutput = io.StringIO()  
		sys.stdout = capturedOutput
		locke.move_boats_through(number_boats)
		sys.stdout = sys.__stdout__ 
		self.assertEqual(capturedOutput.getvalue().strip(), expected_output.strip())
Ejemplo n.º 7
0
	def test_move_boats_through(self):
		a = Locke(5)
        
		with self.assertRaises(ValueError):
			a.move_boats_through(6)

		try:
			a.move_boats_through(6)
		except ValueError as err:
			self.assertEqual(repr(err), "ValueError('Number of boat exceeds locke capacity 5',)")
def test_std_output_tells_story(capsys):
    """given a locke
    when moving boats through
    the standard output tells steps"""
    locke1 = Locke(5)
    boats = 4
    with locke1:
        locke1.move_boats_through(boats)
    captured = capsys.readouterr().out.split("\n")
    assert captured[0] == "run pumps"
    assert captured[1] == "open door1"
    assert captured[2] == "moving boats"
    assert captured[3] == "closing door1"
    assert captured[4] == "starting pumps"
    assert captured[5] == "open door 2"
    assert captured[6] == "moving boats"
    assert captured[7] == "closing door 2"
Ejemplo n.º 9
0
def test_locke_accepts_boats_count_under_limit():
    """given a lock established with a boat limit of 5
    when 5 or less boats are input
    the locke works without exception"""
    locke1 = Locke(5)
    boats = 4
    print(locke1.__dict__)
    with locke1:
        print(locke1.__dict__)
        assert locke1.move_boats_through(boats)
Ejemplo n.º 10
0
	def test_move_boats_greater_than_capacity_fail(self):
		number_boats = 12
		capacity = 10
		locke = Locke(capacity)		
		with self.assertRaises(ValueError):
			locke.move_boats_through(number_boats)
Ejemplo n.º 11
0
def test_entry_conditions_valid():
    locke = Locke(5)
    locke.move_boats_through(5)

    assert locke.check_entry_conditions() is True
Ejemplo n.º 12
0
def test_boats():
    locke = Locke(5)
    locke.move_boats_through(5)

    assert locke.boats == 5