Best Python code snippet using autotest_python
decorator.py
Source:decorator.py
...18# def get_positive_effects(self):19# return self.positive_effects.copy()20# def get_negative_effects(self):21# return self.negative_effects.copy()22# def get_stats(self):23# return self.stats.copy()24class AbstractEffect(Hero, ABC):25 def __init__(self, base):26 self.base = base27 @abstractmethod28 def get_positive_effects(self):29 pass30 @abstractmethod31 def get_negative_effects(self):32 pass33 @abstractmethod34 def get_stats(self):35 pass36class AbstractPositive(AbstractEffect):37 def get_negative_effects(self):38 return self.base.get_negative_effects()39class AbstractNegative(AbstractEffect):40 def get_positive_effects(self):41 return self.base.get_positive_effects()42class Berserk(AbstractPositive):43 def get_stats(self):44 stats = self.base.get_stats()45 stats['Strength'] += 746 stats['Endurance'] += 747 stats['Agility'] += 748 stats['Luck'] += 749 50 stats['Perception'] -= 351 stats['Charisma'] -= 352 stats['Intelligence'] -= 353 stats['HP'] += 5054 return stats55 def get_positive_effects(self):56 positive = self.base.get_positive_effects()57 positive.append('Berserk')58 return positive.copy()59class Blessing(AbstractPositive):60 def get_stats(self):61 stats = self.base.get_stats()62 stats['Strength'] += 263 stats['Endurance'] += 264 stats['Agility'] += 265 stats['Luck'] += 266 stats['Perception'] += 267 stats['Charisma'] += 268 stats['Intelligence'] += 269 return stats70 def get_positive_effects(self):71 positive = self.base.get_positive_effects()72 positive.append('Blessing')73 return positive.copy()74class Weakness(AbstractNegative):75 def get_stats(self):76 stats = self.base.get_stats()77 stats['Strength'] -= 478 stats['Endurance'] -= 479 stats['Agility'] -= 480 return stats81 def get_negative_effects(self):82 negative = self.base.get_negative_effects()83 negative.append('Weakness')84 return negative.copy()85class Curse(AbstractNegative):86 def get_stats(self):87 stats = self.base.get_stats()88 stats['Strength'] -= 289 stats['Endurance'] -= 290 stats['Agility'] -= 291 stats['Luck'] -= 292 stats['Perception'] -= 293 stats['Charisma'] -= 294 stats['Intelligence'] -= 295 return stats96 97 def get_negative_effects(self):98 negative = self.base.get_negative_effects()99 negative.append('Curse')100 return negative.copy()101class EvilEye(AbstractNegative):102 def get_stats(self):103 stats = self.base.get_stats()104 stats['Luck'] -= 10105 return stats106 107 def get_negative_effects(self):108 negative = self.base.get_negative_effects()109 negative.append('EvilEye')110 return negative.copy()111if __name__ == '__main__':112 # Ñоздадим геÑоÑ113 hero = Hero()114 # пÑовеÑим пÑавилÑноÑÑÑ Ñ
аÑакÑеÑиÑÑик по-ÑмолÑаниÑ115 assert hero.get_stats() == {'HP': 128,116 'MP': 42,117 'SP': 100,118 'Strength': 15,119 'Perception': 4,120 'Endurance': 8,121 'Charisma': 2,122 'Intelligence': 3,123 'Agility': 8,124 'Luck': 1}125 # пÑовеÑим ÑпиÑок оÑÑиÑаÑелÑнÑÑ
ÑÑÑекÑов126 assert hero.get_negative_effects() == []127 # пÑовеÑим ÑпиÑок положиÑелÑнÑÑ
ÑÑÑекÑов128 assert hero.get_positive_effects() == []129 # наложим ÑÑÑÐµÐºÑ Berserk130 brs1 = Berserk(hero)131 # пÑовеÑим пÑавилÑноÑÑÑ Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ Ñ
аÑакÑеÑиÑÑик132 assert brs1.get_stats() == {'HP': 178,133 'MP': 42,134 'SP': 100,135 'Strength': 22,136 'Perception': 1,137 'Endurance': 15,138 'Charisma': -1,139 'Intelligence': 0,140 'Agility': 15,141 'Luck': 8}142 # пÑовеÑим неизменноÑÑÑ ÑпиÑка оÑÑиÑаÑелÑнÑÑ
ÑÑÑекÑов143 assert brs1.get_negative_effects() == []144 # пÑовеÑим, ÑÑо в ÑпиÑок положиÑелÑнÑÑ
ÑÑÑекÑов бÑл добавлен Berserk145 assert brs1.get_positive_effects() == ['Berserk']146 # повÑоÑное наложение ÑÑÑекÑа Berserk147 brs2 = Berserk(brs1)148 # наложение ÑÑÑекÑа Curse149 cur1 = Curse(brs2)150 # пÑовеÑим пÑавилÑноÑÑÑ Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ Ñ
аÑакÑеÑиÑÑик151 assert cur1.get_stats() == {'HP': 228,152 'MP': 42,153 'SP': 100,154 'Strength': 27,155 'Perception': -4,156 'Endurance': 20,157 'Charisma': -6,158 'Intelligence': -5,159 'Agility': 20,160 'Luck': 13}161 # пÑовеÑим пÑавилÑноÑÑÑ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ ÑÑÑекÑов в ÑпиÑок положиÑелÑнÑÑ
ÑÑÑекÑов162 assert cur1.get_positive_effects() == ['Berserk', 'Berserk']163 # пÑовеÑим пÑавилÑноÑÑÑ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ ÑÑÑекÑов в ÑпиÑок оÑÑиÑаÑелÑнÑÑ
ÑÑÑекÑов164 assert cur1.get_negative_effects() == ['Curse']165 # ÑнÑÑие ÑÑÑекÑа Berserk166 cur1.base = brs1167 # пÑовеÑим пÑавилÑноÑÑÑ Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ Ñ
аÑакÑеÑиÑÑик168 assert cur1.get_stats() == {'HP': 178,169 'MP': 42,170 'SP': 100,171 'Strength': 20,172 'Perception': -1,173 'Endurance': 13,174 'Charisma': -3,175 'Intelligence': -2,176 'Agility': 13,177 'Luck': 6}178 # пÑовеÑим пÑавилÑноÑÑÑ ÑÐ´Ð°Ð»ÐµÐ½Ð¸Ñ ÑÑÑекÑов из ÑпиÑка положиÑелÑнÑÑ
ÑÑÑекÑов179 assert cur1.get_positive_effects() == ['Berserk']180 # пÑовеÑим пÑавилÑноÑÑÑ ÑÑÑекÑов в ÑпиÑке оÑÑиÑаÑелÑнÑÑ
ÑÑÑекÑов181 assert cur1.get_negative_effects() == ['Curse']182 # пÑовеÑим незменноÑÑÑ Ñ
аÑакÑеÑиÑÑик Ñ Ð¾Ð±ÑекÑа hero183 assert hero.get_stats() == {'HP': 128,184 'MP': 42,185 'SP': 100,186 'Strength': 15,187 'Perception': 4,188 'Endurance': 8,189 'Charisma': 2,190 'Intelligence': 3,191 'Agility': 8,192 'Luck': 1}...
3 week - pattern_decorator.py
Source:3 week - pattern_decorator.py
...18 def get_positive_effects(self):19 return self.positive_effects.copy()20 def get_negative_effects(self):21 return self.negative_effects.copy()22 def get_stats(self):23 return self.stats.copy()24class AbstractEffect(ABC, Hero):25 def __init__(self, base):26 self.base = base27 self.basic_feature = ("Strength", "Endurance", "Agility", "Luck", "Perception", "Charisma", "Intelligence")28 @abstractmethod29 def get_positive_effects(self):30 return self.positive_effects31 @abstractmethod32 def get_negative_effects(self):33 return self.negative_effects34 @abstractmethod35 def get_stats(self):36 pass37class AbstractPositive(AbstractEffect):38 def get_negative_effects(self):39 return self.base.get_negative_effects()40class AbstractNegative(AbstractEffect):41 def get_positive_effects(self):42 return self.base.get_positive_effects()43class Berserk(AbstractPositive):44 # УвелиÑÐ¸Ð²Ð°ÐµÑ Ñ
аÑакÑеÑиÑÑики: Сила, ÐÑноÑливоÑÑÑ, ÐовкоÑÑÑ, УдаÑа на 7;45 # ÑменÑÑÐ°ÐµÑ Ñ
аÑакÑеÑиÑÑики: ÐоÑпÑиÑÑие, ХаÑизма, ÐнÑÐµÐ»Ð»ÐµÐºÑ Ð½Ð° 3;46 # колиÑеÑÑво ÐµÐ´Ð¸Ð½Ð¸Ñ Ð·Ð´Ð¾ÑовÑÑ ÑвелиÑиваеÑÑÑ Ð½Ð° 50.47 def get_positive_effects(self):48 return self.base.get_positive_effects() + ["Berserk"]49 def get_stats(self):50 stats = self.base.get_stats()51 stats["Strength"] += 752 stats["Endurance"] += 753 stats["Agility"] += 754 stats["Luck"] += 755 stats["Perception"] -= 356 stats["Charisma"] -= 357 stats["Intelligence"] -= 358 stats["HP"] += 5059 return stats60class Blessing(AbstractPositive):61 # УвелиÑÐ¸Ð²Ð°ÐµÑ Ð²Ñе оÑновнÑе Ñ
аÑакÑеÑиÑÑики на 2.62 def get_positive_effects(self):63 return self.base.get_positive_effects() + ["Blessing"]64 def get_stats(self):65 stats = self.base.get_stats()66 for i in self.basic_feature:67 stats[i] += 268 return stats69class Weakness(AbstractNegative):70 # УменÑÑÐ°ÐµÑ Ñ
аÑакÑеÑиÑÑики: Сила, ÐÑноÑливоÑÑÑ, ÐовкоÑÑÑ Ð½Ð° 4.71 def get_negative_effects(self):72 return self.base.get_negative_effects() + ['Weakness']73 def get_stats(self):74 stats = self.base.get_stats()75 stats["Strength"] -= 476 stats["Endurance"] -= 477 stats["Agility"] -= 478 return stats79class Curse(AbstractNegative):80 # УменÑÑÐ°ÐµÑ Ñ
аÑакÑеÑиÑÑÐ¸ÐºÑ Ð£Ð´Ð°Ñа на 10.81 def get_negative_effects(self):82 return self.base.get_negative_effects() + ['Curse']83 def get_stats(self):84 stats = self.base.get_stats()85 for i in self.basic_feature:86 stats[i] -= 287 return stats88class EvilEye(AbstractNegative):89 # УменÑÑÐ°ÐµÑ Ð²Ñе оÑновнÑе Ñ
аÑакÑеÑиÑÑики на 2.90 def get_negative_effects(self):91 return self.base.get_negative_effects() + ['EvilEye']92 def get_stats(self):93 stats = self.base.get_stats()94 stats["Luck"] -= 1095 return stats96hero = Hero()97print(hero.get_stats())98print(hero.stats)99print(hero.get_negative_effects())100print(hero.get_positive_effects())101# # накладÑваем ÑÑÑекÑ102brs1 = Berserk(hero)103print(brs1.get_stats())104print(brs1.get_negative_effects())105print(brs1.get_positive_effects())106#107# # накладÑваем ÑÑÑекÑÑ108brs2 = Berserk(brs1)109cur1 = Curse(brs2)110print(cur1.get_stats())111print(cur1.get_positive_effects())112print(cur1.get_negative_effects())113#114# # Ñнимаем ÑÑÑÐµÐºÑ Berserk115cur1.base = brs1116print(cur1.get_stats())117print(cur1.get_positive_effects())...
test.py
Source:test.py
...8 @abstractmethod9 def get_negative_effects(self):10 pass11 @abstractmethod12 def get_stats(self):13 pass14class AbstractPositive(AbstractEffect):15 @abstractmethod16 def get_positive_effects(self):17 pass18 def get_negative_effects(self):19 return self.base.get_negative_effects()20 @abstractmethod21 def get_stats(self):22 pass23class AbstractNegative(AbstractEffect):24 def get_positive_effects(self):25 return self.base.get_positive_effects()26 @abstractmethod27 def get_negative_effects(self):28 pass29 @abstractmethod30 def get_stats(self):31 pass32class Berserk(AbstractPositive):33 def get_positive_effects(self):34 return self.base.get_positive_effects() + [self.__class__.__name__]35 def get_stats(self):36 stats = self.base.get_stats()37 stats['HP'] += 5038 stats['Strength'] += 739 stats['Endurance'] += 740 stats['Agility'] += 741 stats['Luck'] += 742 stats['Perception'] -= 343 stats['Charisma'] -= 344 stats['Intelligence'] -= 345 return stats46class Blessing(AbstractPositive):47 def get_positive_effects(self):48 return self.base.get_positive_effects() + [self.__class__.__name__]49 def get_stats(self):50 stats = self.base.get_stats()51 stats['Strength'] += 2 52 stats['Perception'] += 2 53 stats['Endurance'] += 2 54 stats['Charisma'] += 2 55 stats['Intelligence'] += 2 56 stats['Agility'] += 2 57 stats['Luck'] += 2 58 return stats59class Weakness(AbstractNegative):60 def get_negative_effects(self):61 return self.base.get_negative_effects() + [self.__class__.__name__]62 def get_stats(self):63 stats = self.base.get_stats()64 stats['Strength'] -= 4 65 stats['Endurance'] -= 4 66 stats['Agility'] -= 4 67 return stats68class EvilEye(AbstractNegative):69 def get_negative_effects(self):70 return self.base.get_negative_effects() + [self.__class__.__name__]71 def get_stats(self):72 stats = self.base.get_stats()73 stats['Luck'] -= 10 74 return stats75class Curse(AbstractNegative):76 def get_negative_effects(self):77 return self.base.get_negative_effects() + [self.__class__.__name__]78 def get_stats(self):79 stats = self.base.get_stats()80 stats['Strength'] -= 2 81 stats['Perception'] -= 2 82 stats['Endurance'] -= 2 83 stats['Charisma'] -= 2 84 stats['Intelligence'] -= 2 85 stats['Agility'] -= 2 86 stats['Luck'] -= 2 ...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!