def setUp(self): """This method is run once before _each_ test method is executed""" self.garage = Garage() self.bike = Bike() self.bike2 = Bike() self.bike3 = Bike() self.bike4 = Bike() self.bike5 = Bike() self.bike6 = Bike() self.bike7 = Bike()
def setUp(self): """This method is run once before _each_ test method is executed""" self.container = Container(6) self.other_container = Container(5) self.bike = Bike() self.bike2 = Bike() self.bike3 = Bike() self.bike4 = Bike() self.bike5 = Bike() self.bike6 = Bike() self.bike7 = Bike()
def on_press(self, *args, **kwargs): _screen = self._current_screen() menu_screen = ValidObject.menu_screen(_screen.manager.get_screen('menu')) bikes_screen = ValidObject.bikes_screen(_screen.manager.get_screen('bikes')) maps_screen = ValidObject.maps_screen(_screen.manager.get_screen('maps')) shop_screen = ValidObject.shop_screen(_screen.manager.get_screen('shop')) screens = [menu_screen, bikes_screen, maps_screen, shop_screen] if 'BikesScreen' == _screen.__class__.__name__: if not app_config('bike', 'title'): bike_model = get_bike_by_title(bikes_screen.ids['title'].text) rest_rm = calc_rest_rm(bike_model.price) if Bike.buy(bike_model): RightPanelBtn.change_rm(screens, rest_rm) RightPanelBtn.change_character_wrap(bikes_screen.ids['character_wrap_price'], bike_model.price) RightPanelBtn.change_character_wrap(bikes_screen.ids['character_wrap_power'], bike_model.power) RightPanelBtn.change_character_wrap(bikes_screen.ids['character_wrap_speed'], bike_model.speed) RightPanelBtn.change_character_wrap(bikes_screen.ids['character_wrap_acceleration'], bike_model.acceleration) RightPanelBtn.change_character_wrap(bikes_screen.ids['character_wrap_agility'], bike_model.agility) RightPanelBtn.cancel_animation_button(screens, 'left_panel_menu_bikes') self.init_item(menu_screen.init_bike) RightPanelBtn.change_bottom_right_btn(menu_screen) bikes_screen.ids['title'].color = UColor.hex(UColor.WHITE) else: Clock.schedule_once(self._create_animation_fail, 0) Clock.schedule_once(self._clear_animation, .5) elif 'MapsScreen' == _screen.__class__.__name__: if not app_config('map', 'title'): map_model = get_map_by_title(maps_screen.ids['title'].text) rest_rm = calc_rest_rm(map_model.price) if BaseLevel.buy(map_model): RightPanelBtn.change_rm(screens, rest_rm) RightPanelBtn.change_character_wrap(maps_screen.ids['character_wrap_price'], map_model.price) RightPanelBtn.change_character_wrap(maps_screen.ids['character_wrap_record'], '/dev/') RightPanelBtn.change_character_wrap(maps_screen.ids['character_wrap_level'], map_model.level) RightPanelBtn.change_character_wrap(maps_screen.ids['character_wrap_map'], map_model.map) RightPanelBtn.change_character_wrap(maps_screen.ids['character_wrap_total_way'], map_model.total_way) RightPanelBtn.cancel_animation_button(screens, 'left_panel_menu_maps') self.init_item(menu_screen.init_map) RightPanelBtn.change_bottom_right_btn(menu_screen) maps_screen.ids['title'].color = UColor.hex(UColor.WHITE) else: Clock.schedule_once(self._create_animation_fail, 0) Clock.schedule_once(self._clear_animation, .5)
def test_bike_buy_success(self): self.set_app() _bike = get_bike_by_title('Default') menu_screen = ValidObject.menu_screen(self.sm.get_screen('menu')) self.assertEqual( menu_screen.get_label_by_text('No bike').text, 'No bike') self.assertEqual(_bike.title, 'Default') self.assertTrue(Bike.buy(_bike)) self.assertEqual(_bike.title, Cache.get('bike', 'title')) self.assertEqual(_bike.power, Cache.get('bike', 'power')) self.assertEqual(_bike.speed, Cache.get('bike', 'speed')) self.assertEqual(_bike.acceleration, Cache.get('bike', 'acceleration')) self.assertEqual(_bike.agility, Cache.get('bike', 'agility')) self.assertEqual(RM - int(_bike.price), Cache.get('bike', 'rm'))
class TestPerson(object): @classmethod def setup_class(klass): """This method is run once for each class before any tests are run""" @classmethod def teardown_class(klass): """This method is run once for each class _after_ all tests are run""" def setUp(self): """This method is run once before _each_ test method is executed""" self.person = Person() self.bike = Bike() self.bike2 = Bike() self.station = Station() def teardown(self): """This method is run once after _each_ test method is executed""" pass def test_person_has_no_bikes(self): assert_equal(len(self.person.bikes), 0) def test_person_can_have_a_bike(self): self.person.rides(self.bike) assert_equal(len(self.person.bikes), 1) assert_in(self.bike, self.person.bikes) def test_person_cannot_ride_a_broken_bike(self): self.bike.break_bike() assert_equal(self.person.rides(self.bike), "Cannot ride a broken bike") def test_person_can_release_a_bike(self): self.person.rides(self.bike) self.person.release(self.bike) assert_equal(len(self.person.bikes), 0) def test_person_can_have_only_one_bike(self): assert_equal(self.person.capacity, 1) def test_person_is_not_full(self): assert_equal(self.person.has_bike(), "doesn\'t have any bike") def test_person_has_a_bike(self): self.person.rides(self.bike) assert_equal(self.person.has_bike(), "has one bike") def test_person_cannot_have_two_bikes(self): self.person.rides(self.bike) self.person.rides(self.bike2) assert_equal(self.person.rides(self.bike2), "Cannot ride more than one bike") def test_person_falls_and_bike_is_broken(self): self.person.rides(self.bike) self.person.falls_from(self.bike) assert_true(self.bike.broken) def test_person_cannot_rent_if_station_has_no_bikes(self): assert_equal(self.person.rent_from(self.bike, self.station), "There are no bikes here") def test_person_can_rent_bike_from_station(self): self.station.dock(self.bike) self.person.rent_from(self.bike, self.station) assert_in(self.bike, self.person.bikes) assert_not_in(self.bike, self.station.bikes) def test_cannot_rent_a_broken_bike_from_the_station(self): self.bike.break_bike() self.station.dock(self.bike) assert_equal(self.person.rent_from(self.bike, self.station), "This bike is broken") def test_person_can_return_bike(self): self.station.dock(self.bike) self.person.rent_from(self.bike, self.station) self.person.return_to(self.bike, self.station) assert_in(self.bike, self.station.bikes)
def setUp(self): """This method is run once before _each_ test method is executed""" self.person = Person() self.bike = Bike() self.bike2 = Bike() self.station = Station()
class TestContainer(object): @classmethod def setup_class(klass): """This method is run once for each class before any tests are run""" @classmethod def teardown_class(klass): """This method is run once for each class _after_ all tests are run""" def setUp(self): """This method is run once before _each_ test method is executed""" self.container = Container(6) self.other_container = Container(5) self.bike = Bike() self.bike2 = Bike() self.bike3 = Bike() self.bike4 = Bike() self.bike5 = Bike() self.bike6 = Bike() self.bike7 = Bike() def teardown(self): """This method is run once after _each_ test method is executed""" pass def test_container_has_no_bikes(self): assert_equal(len(self.container.bikes), 0) def test_container_can_have_a_bike(self): self.container.dock(self.bike) assert_equal(len(self.container.bikes), 1) assert_in(self.bike, self.container.bikes) def test_container_can_release_a_bike(self): self.container.dock(self.bike) self.container.release(self.bike) assert_equal(len(self.container.bikes), 0) def test_container_can_release_a_bike_if_has_one(self): assert_equal(self.container.release(self.bike), "There are no bikes here") def test_container_has_a_maximum_capacity(self): assert_equal(self.container.capacity, 6) def test_container_is_not_full(self): self.container.dock(self.bike) self.container.dock(self.bike2) assert_equal(self.container.is_full(), "not full") def test_container_can_be_full(self): self.container.dock(self.bike) self.container.dock(self.bike2) self.container.dock(self.bike3) self.container.dock(self.bike4) self.container.dock(self.bike5) self.container.dock(self.bike6) assert_equal(self.container.is_full(), "full") def test_container_cannot_dock_more_than_six_bikes(self): self.container.dock(self.bike) self.container.dock(self.bike2) self.container.dock(self.bike3) self.container.dock(self.bike4) self.container.dock(self.bike5) self.container.dock(self.bike6) assert_equal(self.container.dock(self.bike7), "Cannot dock any more bikes") def test_container_has_broken_bikes(self): self.bike.break_bike() self.container.dock(self.bike) self.container.dock(self.bike2) assert_in(self.bike, self.container.broken_bikes) def test_container_has_available_bikes(self): self.container.dock(self.bike) self.container.dock(self.bike2) assert_in(self.bike, self.container.available_bikes) assert_in(self.bike2, self.container.available_bikes) def test_if_a_bike_is_already_docked(self): self.container.dock(self.bike) assert_true(self.container.has_already(self.bike)) def test_bike_cannot_be_docked_twice(self): self.container.dock(self.bike) assert_equal(self.container.dock(self.bike), "Cannot dock the same bike twice") def test_can_release_all_broken_bikes(self): self.bike.break_bike() self.bike2.break_bike() self.container.dock(self.bike) self.container.dock(self.bike2) self.container.release_broken_bikes_to(self.other_container) assert_in(self.bike, self.other_container.bikes) assert_in(self.bike2, self.other_container.bikes) assert_not_in(self.bike, self.container.bikes) assert_not_in(self.bike2, self.container.bikes) def test_error_message_if_no_broken_bikes(self): self.container.dock(self.bike) assert_equal(self.container.release_broken_bikes_to(self.other_container), "There are no broken bikes here") def test_can_release_all_available_bikes(self): self.container.dock(self.bike) self.container.dock(self.bike2) self.container.release_available_bikes_to(self.other_container) assert_in(self.bike, self.other_container.bikes) assert_in(self.bike2, self.other_container.bikes) assert_not_in(self.bike, self.container.bikes) assert_not_in(self.bike2, self.container.bikes) def test_error_message_if_no_available_bikes(self): self.bike.break_bike() self.container.dock(self.bike) assert_equal(self.container.release_available_bikes_to(self.other_container), "There are no available bikes here")
class TestBike(object): @classmethod def setup_class(klass): """This method is run once for each class before any tests are run""" @classmethod def teardown_class(klass): """This method is run once for each class _after_ all tests are run""" def setUp(self): """This method is run once before _each_ test method is executed""" self.bike = Bike() def teardown(self): """This method is run once after _each_ test method is executed""" pass def test_bike_not_broken(self): assert_false(self.bike.broken) def test_bike_can_be_broken(self): self.bike.break_bike() assert_true(self.bike.broken) def test_bike_can_be_fixed(self): self.bike.break_bike() self.bike.fix_bike() assert_false(self.bike.broken) def test_fixed_status_of_the_bike_when_created(self): assert_equal(self.bike.status, "fixed") def test_broken_status_of_the_bike_when_broken(self): self.bike.break_bike() assert_equal(self.bike.status, "broken") def test_fixed_status_of_the_bike_when_fixed(self): self.bike.break_bike() self.bike.fix_bike() assert_equal(self.bike.status, "fixed")
def setUp(self): """This method is run once before _each_ test method is executed""" self.bike = Bike()
class TestVan(object): @classmethod def setup_class(klass): """This method is run once for each class before any tests are run""" @classmethod def teardown_class(klass): """This method is run once for each class _after_ all tests are run""" def setUp(self): """This method is run once before _each_ test method is executed""" self.garage = Garage() self.bike = Bike() self.bike2 = Bike() self.bike3 = Bike() self.bike4 = Bike() self.bike5 = Bike() self.bike6 = Bike() self.bike7 = Bike() def teardown(self): """This method is run once after _each_ test method is executed""" pass def test_garage_has_capacity_of_six(self): assert_equal(self.garage.capacity, 6) def test_garage_is_not_full(self): self.garage.dock(self.bike) self.garage.dock(self.bike2) assert_equal(self.garage.is_full(), "not full") def test_garage_can_be_full(self): self.garage.dock(self.bike) self.garage.dock(self.bike2) self.garage.dock(self.bike3) self.garage.dock(self.bike4) self.garage.dock(self.bike5) self.garage.dock(self.bike6) assert_equal(self.garage.is_full(), "full") def test_garage_cannot_dock_more_than_five_bikes(self): self.garage.dock(self.bike) self.garage.dock(self.bike2) self.garage.dock(self.bike3) self.garage.dock(self.bike4) self.garage.dock(self.bike5) self.garage.dock(self.bike6) assert_equal(self.garage.dock(self.bike7), "Cannot dock any more bikes") def test_can_fix_one_broken_bike(self): self.bike.break_bike() self.garage.dock(self.bike) self.garage.fix_bikes() assert_in(self.bike, self.garage.available_bikes) def test_can_fix_all_broken_bikes(self): self.bike.break_bike() self.bike2.break_bike() self.garage.dock(self.bike) self.garage.dock(self.bike2) self.garage.fix_bikes() assert_in(self.bike, self.garage.available_bikes) assert_in(self.bike2, self.garage.available_bikes) def test_error_if_no_broken_bikes(self): self.garage.dock(self.bike) assert_equal(self.garage.fix_bikes(), "There are no broken bikes here")