Skip to content

Commit

Permalink
Merge pull request #38 from mkli90/bug/35-getting-rid-off-combine-with
Browse files Browse the repository at this point in the history
#34, #35, #37 - renamed add_to_container, removed combine_with, item appends to parent_container
  • Loading branch information
mvmntjulz committed May 8, 2015
2 parents 2033688 + 5fa27fe commit cbe7e83
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
22 changes: 10 additions & 12 deletions tekmate/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class InvalidCombination(Exception):

def __init__(self, parent_container):
assert parent_container is not None
parent_container.append(self)
self.usable = False
self.obtainable = False
self.parent_container = parent_container
Expand All @@ -23,16 +24,13 @@ def __init__(self, parent_container):
def setup(self): # pragma: no cover
pass

def combine(self, other):
self.combine_with(other)

def combine_with(self, other): # pragma: no cover
def combine(self, other): # pragma: no cover
pass

def remove_from_parent_container(self):
self.parent_container.remove(self)

def add_to_container(self, new_container):
def move_to_container(self, new_container):
new_container.append(self)
self.remove_from_parent_container()
self.parent_container = new_container
Expand All @@ -56,7 +54,7 @@ class Needle(Item):
def get_name(self):
return "Needle"

def combine_with(self, other):
def combine(self, other):
if other.get_name() != "Lock":
raise Item.InvalidCombination
self.remove_from_parent_container()
Expand Down Expand Up @@ -85,7 +83,7 @@ def setup(self):
def get_name(self):
return "ID-Card"

def combine_with(self, other):
def combine(self, other):
if self.has_insufficient_permissions(other):
raise IdCard.AccessDenied
other.usable = True
Expand All @@ -109,7 +107,7 @@ class NotAnIdCard(Exception):
def get_name(self):
return "Card-Reader"

def combine_with(self, other):
def combine(self, other):
if other.get_name() != "ID-Card":
raise CardReader.NotAnIdCard
other.unique_attributes["key_code"] += 1
Expand All @@ -127,7 +125,7 @@ def setup(self):
def get_name(self):
return "Note"

def combine_with(self, other):
def combine(self, other):
if other.get_name() != "Symbols-Folder":
raise Item.InvalidCombination

Expand Down Expand Up @@ -155,7 +153,7 @@ class Telephone(Item):
def get_name(self):
return "Telephone"

def combine_with(self, other):
def combine(self, other):
if other.get_name() != "Telephone-Note":
raise Item.InvalidCombination
other.remove_from_parent_container()
Expand All @@ -168,10 +166,10 @@ def setup(self):
def get_name(self):
return "Flyer"

def combine_with(self, other):
def combine(self, other):
if other.get_name() != "Door":
raise Item.InvalidCombination
key = next(item for item in other.parent_container if item.get_name() == "Key")
if not key.obtainable:
raise Key.NotObtainable
key.add_to_container(self.parent_container)
key.move_to_container(self.parent_container)
2 changes: 1 addition & 1 deletion tekmate/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def render(self):
self.surface.fill((255, 255, 255))
self.surface.blit(self.image, (0, 0))

def draw_player_to_display(self, display): # pragma: no cover
def draw_player_to_display(self, display):
display.blit(self.surface, self.get_position())

def create_surface_and_image(self, factor):
Expand Down
17 changes: 5 additions & 12 deletions tests/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class ItemTestCase(TestCase):
def setUp(self):
self.container = []
self.item = Item(self.container)
self.container.append(self.item)

def test_can_create_item(self):
self.assertEqual("Item", self.item.get_name())

def test_when_created_item_should_be_inside_parent_container(self):
self.assertIn(self.item, self.item.parent_container)

def test_not_obtainable_by_default(self):
self.assertFalse(self.item.obtainable)

Expand All @@ -33,7 +35,7 @@ def __init__(self, parent_container):
super(MockItem, self).__init__(parent_container)
self.called = False

def combine_with(self, other):
def combine(self, other):
self.called = other is item

mock_item = MockItem([])
Expand All @@ -46,7 +48,7 @@ def test_when_remove_from_container_parent_container_loses_item(self):

def test_when_add_to_container_container_should_change(self):
container_new = []
self.item.add_to_container(container_new)
self.item.move_to_container(container_new)
self.assertIn(self.item, container_new)
self.assertNotIn(self.item, self.container)

Expand All @@ -61,13 +63,6 @@ def setUp(self):
self.key = Key(self.world_container)
self.lock = Lock(self.world_container)

self.append_items_to_respective_containers()

def append_items_to_respective_containers(self):
self.container.append(self.needle)
self.world_container.append(self.key)
self.world_container.append(self.lock)

def test_can_create_needle(self):
self.assertEqual("Needle", self.needle.get_name())

Expand Down Expand Up @@ -138,7 +133,6 @@ def setUp(self):
self.folder = SymbolsFolder([])
self.player = Player()
self.note = Note(self.player.bag)
self.player.add_item(self.note)

def test_can_create_note(self):
self.assertEqual("Note", self.note.get_name())
Expand All @@ -164,7 +158,6 @@ def setUp(self):
def setup_player_bag(self):
self.player = Player()
self.tel_note = TelephoneNote(self.player.bag)
self.player.add_item(self.tel_note)

def test_can_create_telephone(self):
self.assertEqual(self.telephone.get_name(), "Telephone")
Expand Down
9 changes: 4 additions & 5 deletions tests/test_ui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
from unittest import TestCase, skip

from mock import patch, call
from mock import patch, call, Mock
import pygame

from tekmate.game import Player
Expand Down Expand Up @@ -44,11 +44,10 @@ def test_when_render_is_called_screen_should_get_cleared_and_image_is_drawn_to_s
expected_argument_for_blit = call(self.player_ui.image, (0, 0))
self.assertBlitArgumentIs(expected_argument_for_blit)

@skip("What has to be tested here?")
def test_when_drawn_player_to_display_expected_argument_should_be_display(self):
display = pygame.display.get_surface()
self.assertEqual(self.player_ui.draw_player_to_display(display), display)

mock_display = Mock()
self.player_ui.draw_player_to_display(mock_display)
mock_display.blit.assert_called_with(self.player_ui.surface, (0, 0))

def assertBlitArgumentIs(self, expected_args):
returned_argument_list_for_blit = self.player_ui.surface.blit.call_args_list
Expand Down

0 comments on commit cbe7e83

Please sign in to comment.