当前位置: 首页>>代码示例>>Python>>正文


Python Inventory.close方法代码示例

本文整理汇总了Python中inventory.Inventory.close方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.close方法的具体用法?Python Inventory.close怎么用?Python Inventory.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inventory.Inventory的用法示例。


在下文中一共展示了Inventory.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CartTest

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import close [as 别名]
class CartTest(unittest.TestCase):
    
    def setUp(self):
        self.cart = Cart()
        self.inv = Inventory()

    def tearDown(self):
        self.inv.close()

    def test_add_items_to_basket(self):
        # Test adding item, make sure it's in cart and inventory updates to reflect that
        old_qty= self.inv.view_qty('item050')
        self.cart.add_item('item050', 10)
        self.assertEqual(self.cart.basket('item050'), 10)
        self.assertEqual(self.inv.view_qty('item050'), old_qty-10)
        self.inv.update_qty('item050', 500)
        # Test adding more to cart than inventory contains
        self.cart._basket['item050'] = 0 # Temporary kluge 
        self.cart.add_item('item050', 600)
        self.assertEqual(self.cart.basket('item050'), 500)
        self.assertEqual(self.inv.view_qty('item050'), 0)
        self.inv.update_qty('item050', 500)

    def test_remove_items_from_basket(self):
        self.cart.add_item('item050', 10)
        self.cart.remove_item('item050',5)
        self.assertEqual(self.cart.basket('item050'), 5)
        self.assertEqual(self.inv.view_qty('item050'), 495)

    def test_edit_items(self):
        # Change to a quantity greater than you already have
        self.cart.edit_item('item050', 50)
        self.cart.edit_item('item050', 70)
        self.assertEqual(self.cart.basket('item050'), 70)
        self.assertEqual(self.inv.view_qty('item050'), 430)
        self.cart.remove_item('item050', 70)
        # Add more than are in inventory
        self.cart.edit_item('item050', 1000)
        self.assertEqual(self.inv.view_qty('item050'), 0)
        self.assertEqual(self.cart.basket('item050'), 500)
        self.cart.remove_item('item050', 500)
        # Change to a quantity less than what you already have
        self.cart.add_item('item050', 100)
        self.cart.edit_item('item050', 50)
        self.assertEqual(self.inv.view_qty('item050'), 450)
        self.assertEqual(self.cart.basket('item050'), 50)
        self.cart.remove_item('item050', 50)
        
    def test_items_total(self):
        self.cart.add_item('item100', 100)
        cost = 100 * self.inv.view_price('item100')
        self.assertEqual(self.cart.items_total(), cost)
        self.cart.remove_item('item100', 100)

    def test_list_items(self):
        self.cart.add_item('item100', 100)
        # Test listing sorted by item name
        for _tuple in self.cart.list_items('item'):
            self.assertEqual(_tuple, ('item100', 100, self.inv.view_price('item100')))
        # Test listing sorted by qty
        for _tuple in self.cart.list_items('price'):
            self.assertEqual(_tuple, ('item100', 100, self.inv.view_price('item100')))
        # Test listing sorted by price
            self.assertEqual(_tuple, ('item100', 100, self.inv.view_price('item100')))
        self.cart.remove_item('item100', 100)
开发者ID:timahutchinson,项目名称:curly-quack,代码行数:67,代码来源:unit_test.py

示例2: InventoryTest

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import close [as 别名]
class InventoryTest(unittest.TestCase):
    
    def setUp(self):
        """Create inventory instance."""
        self.inv = Inventory()

    def tearDown(self):
        """Close database opened by self.inv."""
        self.inv.close()

    def test_add_record_to_database(self):
        nrecords = self.count_records()
        self.inv.add_item('test_item', 15.00, 200)
        self.assertEqual(self.count_records(), nrecords+1)

    def test_remove_record_from_database(self):
        nrecords = self.count_records()
        self.inv.remove_item('test_item')
        self.assertEqual(self.count_records(), nrecords-1)

    def test_query_sort(self):
        for field in ['item', 'price', 'qty', 'updated']:
            for direction in ['ascending', 'descending']:
                count = 0
                for row in self.inv.query_sort(field, direction):
                    count += 1
                self.assertEqual(count, 100)

    def test_count_records(self):
        self.assertEqual(self.count_records(), self.inv.nrecords)

    def test_next_page(self):
        pass

    def test_update_qty(self):
        self.inv.update_qty('item000', 250)
        self.inv.c.execute('SELECT qty FROM inventory WHERE item=?', ('item000',))
        self.assertEqual(self.inv.c.fetchone()[0], 250)
        self.inv.update_qty('item000', 500)

    def test_update_price(self):
        original_price = self.inv.c.execute('SELECT price FROM inventory WHERE item=?', ('item000',)).fetchone()[0]
        self.inv.update_price('item000', 10)
        self.inv.c.execute('SELECT price FROM inventory WHERE item=?', ('item000',))
        self.assertEqual(self.inv.c.fetchone()[0], 10)
        self.inv.update_price('item000', original_price)

    def test_query_by_price(self):
        original_price1 = self.inv.c.execute('SELECT price FROM inventory WHERE item=?', ('item050',)).fetchone()[0]
        original_price2 = self.inv.c.execute('SELECT price FROM inventory WHERE item=?', ('item150',)).fetchone()[0]
        self.inv.update_price('item050', 50)
        self.inv.update_price('item150', 70)
        # Check with low and high price range
        count = 0
        for row in self.inv.query_by_price(40,80):
            count += 1
        self.assertEqual(count, 2)
        # Check with only low price
        count = 0
        for row in self.inv.query_by_price(40):
            count += 1
        self.assertEqual(count, 2)
        # We also expect all records to be returned with no prices set
        count = 0
        for row in self.inv.query_by_price():
            count += 1
        self.assertEqual(count, self.count_records())

    def test_query_by_name(self):
        # Test should return same number of results regardless of sort
        count = 0
        for row in self.inv.query_by_name('item0', 0, 100, 'item'):
            count += 1
        self.assertEqual(count, 100)
        count = 0
        for row in self.inv.query_by_name('item0', 0, 100, 'price'):
            count += 1
        self.assertEqual(count, 100)
        count = 0
        for row in self.inv.query_by_name('item0', 0, 100):
            count += 1
        self.assertEqual(count, 100)
        count = 0
        for row in self.inv.query_by_name('item0'):
            count += 1
        self.assertEqual(count, 100)

    def test_get_qty(self):
        self.inv.update_qty('item100', 1000)
        self.assertEqual(self.inv.view_qty('item100'), 1000)
        self.inv.update_qty('item100', 1000)

    def count_records(self):
        return self.inv.c.execute('SELECT Count(*) FROM inventory').fetchone()[0]
开发者ID:timahutchinson,项目名称:curly-quack,代码行数:96,代码来源:unit_test.py

示例3: Actor

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import close [as 别名]
class Actor(movable_object.Movable_Object):

    is_event_handler = True

    def __init__(self, body):
        cshape = cm.AARectShape(eu.Vector2(0, 0), TILE_SIZE_IN_PIXELS / 2, body.img.height / 2)
        super(Actor, self).__init__(body.img, cshape=cshape)

        self.fight_group = -1

        self.direction = 1

        self.owner = self
        self.body = body(self)
        self.launcher = Launcher(self)
        self.state = "stand"
        self.inventory = Inventory(self)

        self.ground_count = 0
        self.on_ground = False

        self.recovery = 0.0  # Time before moment when acton can be controlled again

    height = property(lambda self: self.body.img.height)
    width = property(lambda self: self.body.img.width)

    def setup_b2body(self):
        super(Actor, self).setup_b2body()
        pix_to_tile = pixels_to_tiles
        rx, ry = pix_to_tile((self.cshape.rx, self.cshape.ry))
        self.b2body.CreateFixture(
            b2.b2FixtureDef(
                shape=b2.b2PolygonShape(
                    vertices=[(-rx, ry), (-rx, -ry + 0.1), (-rx + 0.1, -ry), (rx - 0.1, -ry), (rx, -ry + 0.1), (rx, ry)]
                )
            )
        )
        self.b2body.fixtures[-1].filterData.categoryBits = B2SMTH | B2ACTOR
        self.b2body.CreateFixture(
            b2.b2FixtureDef(shape=b2.b2EdgeShape(vertex1=(-rx, -ry), vertex2=(rx, -ry)), isSensor=True)
        )
        self.b2body.fixtures[-1].filterData.categoryBits = B2GNDSENS
        self.b2body.fixtures[-1].filterData.maskBits = B2LEVEL | B2ACTOR
        self.world.addEventHandler(self.b2body.fixtures[-1], self.on_ground_begin, self.on_ground_end)

    def use_item(self, item_type, trigger, args):  # MAIN or SECONDARY
        if item_type is MAIN:
            item = self.inventory.main_item
        else:
            item = self.inventory.secondary_item

        if not item:
            return
        if trigger and not item.on_use and item.available:
            item.start_use(*args)
        elif trigger and item.on_use and item.available:
            item.continue_use(*args)
        elif not trigger and item.on_use and item.available:
            item.end_use(*args)

    def start_interact_with_item(self, item):
        if item and item.item_update:
            self.schedule(item.item_update)

    def stop_interact_with_item(self, item):
        if item and item.item_update:
            self.unschedule(item.item_update)

    def collide(self, other):
        other._collide_actor(self)

    def _collide_actor(self, other):
        coll.collide_actor_actor(self, other)

    def _collide_hit_zone(self, other):
        coll.collide_actor_hit_zone(self, other)

    def _collide_slash(self, other):
        coll.collide_actor_slash(self, other)

    def activate_trigger(self, trigger):
        self.dispatch_event("on_activate_trigger", trigger, self)

    def put_item(self, item):
        self.inventory.put_item(item)

    def open(self):
        self.inventory.open()

    def close(self):
        self.inventory.close()

    def destroy(self):
        """
        Remove Actor from level
        """
        if self.fight_group > 0:
            for armor in filter(lambda x: (x.attached is not None), self.body.body_parts):
                armor.attached.drop()
            self.fight_group = -1
#.........这里部分代码省略.........
开发者ID:Ecialo,项目名称:Codename-Parzalon,代码行数:103,代码来源:actor.py


注:本文中的inventory.Inventory.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。