How to use obj_name method in hypothesis

Best Python code snippet using hypothesis

test_file.py

Source:test_file.py Github

copy

Full Screen

1import pytest2import salt.utils.win_dacl as win_dacl3from tests.support.mock import patch4pytestmark = [5 pytest.mark.windows_whitelisted,6 pytest.mark.skip_unless_on_windows,7 pytest.mark.destructive_test,8]9@pytest.fixture10def configure_loader_modules(minion_opts):11 return {12 win_dacl: {13 "__opts__": minion_opts,14 },15 }16@pytest.fixture(scope="function")17def test_file():18 with pytest.helpers.temp_file("dacl_test.file") as test_file:19 yield test_file20@pytest.fixture(scope="function")21def test_dir(tmp_path_factory):22 test_dir = tmp_path_factory.mktemp("test_dir")23 yield str(test_dir)24 test_dir.rmdir()25def test_get_set_owner(test_file):26 result = win_dacl.set_owner(27 obj_name=str(test_file), principal="Backup Operators", obj_type="file"28 )29 assert result is True30 result = win_dacl.get_owner(obj_name=str(test_file), obj_type="file")31 assert result == "Backup Operators"32def test_get_set_primary_group(test_file):33 result = win_dacl.set_primary_group(34 obj_name=str(test_file), principal="Backup Operators", obj_type="file"35 )36 assert result is True37 result = win_dacl.get_primary_group(obj_name=str(test_file), obj_type="file")38 assert result == "Backup Operators"39def test_get_set_permissions(test_file):40 result = win_dacl.set_permissions(41 obj_name=str(test_file),42 principal="Backup Operators",43 permissions="full_control",44 access_mode="grant",45 obj_type="file",46 reset_perms=False,47 protected=None,48 )49 assert result is True50 expected = {51 "Not Inherited": {52 "Backup Operators": {53 "grant": {54 "applies to": "This folder only",55 "permissions": "Full control",56 }57 }58 }59 }60 result = win_dacl.get_permissions(61 obj_name=str(test_file),62 principal="Backup Operators",63 obj_type="file",64 )65 assert result == expected66def test_applies_to_this_folder_only(test_dir):67 """68 #6010369 """70 result = win_dacl.set_permissions(71 obj_name=test_dir,72 principal="Backup Operators",73 permissions="full_control",74 access_mode="grant",75 applies_to="this_folder_only",76 obj_type="file",77 reset_perms=False,78 protected=None,79 )80 assert result is True81 expected = {82 "Not Inherited": {83 "Backup Operators": {84 "grant": {85 "applies to": "This folder only",86 "permissions": "Full control",87 }88 }89 }90 }91 result = win_dacl.get_permissions(92 obj_name=test_dir,93 principal="Backup Operators",94 obj_type="file",95 )96 assert result == expected97def test_applies_to_this_folder_files(test_dir):98 """99 #60103100 """101 result = win_dacl.set_permissions(102 obj_name=test_dir,103 principal="Backup Operators",104 permissions="full_control",105 access_mode="grant",106 applies_to="this_folder_files",107 obj_type="file",108 reset_perms=False,109 protected=None,110 )111 assert result is True112 expected = {113 "Not Inherited": {114 "Backup Operators": {115 "grant": {116 "applies to": "This folder and files",117 "permissions": "Full control",118 }119 }120 }121 }122 result = win_dacl.get_permissions(123 obj_name=test_dir,124 principal="Backup Operators",125 obj_type="file",126 )127 assert result == expected128def test_applies_to_this_folder_subfolders(test_dir):129 """130 #60103131 """132 result = win_dacl.set_permissions(133 obj_name=test_dir,134 principal="Backup Operators",135 permissions="full_control",136 access_mode="grant",137 applies_to="this_folder_subfolders",138 obj_type="file",139 reset_perms=False,140 protected=None,141 )142 assert result is True143 expected = {144 "Not Inherited": {145 "Backup Operators": {146 "grant": {147 "applies to": "This folder and subfolders",148 "permissions": "Full control",149 }150 }151 }152 }153 result = win_dacl.get_permissions(154 obj_name=test_dir,155 principal="Backup Operators",156 obj_type="file",157 )158 assert result == expected159def test_applies_to_this_folder_subfolders_files(test_dir):160 """161 #60103162 """163 result = win_dacl.set_permissions(164 obj_name=test_dir,165 principal="Backup Operators",166 permissions="full_control",167 access_mode="grant",168 applies_to="this_folder_subfolders_files",169 obj_type="file",170 reset_perms=False,171 protected=None,172 )173 assert result is True174 expected = {175 "Not Inherited": {176 "Backup Operators": {177 "grant": {178 "applies to": "This folder, subfolders and files",179 "permissions": "Full control",180 }181 }182 }183 }184 result = win_dacl.get_permissions(185 obj_name=test_dir,186 principal="Backup Operators",187 obj_type="file",188 )189 assert result == expected190def test_applies_to_files_only(test_dir):191 """192 #60103193 """194 result = win_dacl.set_permissions(195 obj_name=test_dir,196 principal="Backup Operators",197 permissions="full_control",198 access_mode="grant",199 applies_to="files_only",200 obj_type="file",201 reset_perms=False,202 protected=None,203 )204 assert result is True205 expected = {206 "Not Inherited": {207 "Backup Operators": {208 "grant": {209 "applies to": "Files only",210 "permissions": "Full control",211 }212 }213 }214 }215 result = win_dacl.get_permissions(216 obj_name=test_dir,217 principal="Backup Operators",218 obj_type="file",219 )220 assert result == expected221def test_applies_to_subfolders_only(test_dir):222 """223 #60103224 """225 result = win_dacl.set_permissions(226 obj_name=test_dir,227 principal="Backup Operators",228 permissions="full_control",229 access_mode="grant",230 applies_to="subfolders_only",231 obj_type="file",232 reset_perms=False,233 protected=None,234 )235 assert result is True236 expected = {237 "Not Inherited": {238 "Backup Operators": {239 "grant": {240 "applies to": "Subfolders only",241 "permissions": "Full control",242 }243 }244 }245 }246 result = win_dacl.get_permissions(247 obj_name=test_dir,248 principal="Backup Operators",249 obj_type="file",250 )251 assert result == expected252def test_applies_to_subfolders_files(test_dir):253 """254 #60103255 """256 result = win_dacl.set_permissions(257 obj_name=test_dir,258 principal="Backup Operators",259 permissions="full_control",260 access_mode="grant",261 applies_to="subfolders_files",262 obj_type="file",263 reset_perms=False,264 protected=None,265 )266 assert result is True267 expected = {268 "Not Inherited": {269 "Backup Operators": {270 "grant": {271 "applies to": "Subfolders and files only",272 "permissions": "Full control",273 }274 }275 }276 }277 result = win_dacl.get_permissions(278 obj_name=test_dir,279 principal="Backup Operators",280 obj_type="file",281 )282 assert result == expected283def test_has_permission_exact_match(test_file):284 result = win_dacl.set_permissions(285 obj_name=str(test_file),286 principal="Backup Operators",287 permissions="full_control",288 access_mode="grant",289 obj_type="file",290 reset_perms=False,291 protected=None,292 )293 assert result is True294 # Test has_permission exact295 result = win_dacl.has_permission(296 obj_name=str(test_file),297 principal="Backup Operators",298 permission="full_control",299 access_mode="grant",300 obj_type="file",301 exact=True,302 )303 assert result is True304def test_has_permission_exact_no_match(test_file):305 result = win_dacl.set_permissions(306 obj_name=str(test_file),307 principal="Backup Operators",308 permissions="full_control",309 access_mode="grant",310 obj_type="file",311 reset_perms=False,312 protected=None,313 )314 assert result is True315 # Test has_permission exact316 result = win_dacl.has_permission(317 obj_name=str(test_file),318 principal="Backup Operators",319 permission="read",320 access_mode="grant",321 obj_type="file",322 exact=True,323 )324 assert result is False325def test_has_permission_contains(test_file):326 result = win_dacl.set_permissions(327 obj_name=str(test_file),328 principal="Backup Operators",329 permissions="full_control",330 access_mode="grant",331 obj_type="file",332 reset_perms=False,333 protected=None,334 )335 assert result is True336 # Test has_permission exact337 result = win_dacl.has_permission(338 obj_name=str(test_file),339 principal="Backup Operators",340 permission="read",341 access_mode="grant",342 obj_type="file",343 exact=False,344 )345 assert result is True346def test_has_permission_contains_advanced(test_file):347 result = win_dacl.set_permissions(348 obj_name=str(test_file),349 principal="Backup Operators",350 permissions="full_control",351 access_mode="grant",352 obj_type="file",353 reset_perms=False,354 protected=None,355 )356 assert result is True357 # Test has_permission exact358 result = win_dacl.has_permission(359 obj_name=str(test_file),360 principal="Backup Operators",361 permission="read_data",362 access_mode="grant",363 obj_type="file",364 exact=False,365 )366 assert result is True367def test_has_permission_missing(test_file):368 result = win_dacl.set_permissions(369 obj_name=str(test_file),370 principal="Backup Operators",371 permissions="read_execute",372 access_mode="grant",373 obj_type="file",374 reset_perms=False,375 protected=None,376 )377 assert result is True378 # Test has_permission not exact379 result = win_dacl.has_permission(380 obj_name=str(test_file),381 principal="Backup Operators",382 permission="write",383 access_mode="grant",384 obj_type="file",385 exact=False,386 )387 assert result is False388def test_has_permission_missing_advanced(test_file):389 result = win_dacl.set_permissions(390 obj_name=str(test_file),391 principal="Backup Operators",392 permissions="read_execute",393 access_mode="grant",394 obj_type="file",395 reset_perms=False,396 protected=None,397 )398 assert result is True399 # Test has_permission not exact400 result = win_dacl.has_permission(401 obj_name=str(test_file),402 principal="Backup Operators",403 permission="write_data",404 access_mode="grant",405 obj_type="file",406 exact=False,407 )408def test_has_permissions_contains(test_file):409 result = win_dacl.set_permissions(410 obj_name=str(test_file),411 principal="Backup Operators",412 permissions="full_control",413 access_mode="grant",414 obj_type="file",415 reset_perms=False,416 protected=None,417 )418 assert result is True419 # Test has_permissions exact420 result = win_dacl.has_permissions(421 obj_name=str(test_file),422 principal="Backup Operators",423 permissions=["read", "write"],424 access_mode="grant",425 obj_type="file",426 exact=False,427 )428 assert result is True429def test_has_permissions_contains_advanced(test_file):430 result = win_dacl.set_permissions(431 obj_name=str(test_file),432 principal="Backup Operators",433 permissions="full_control",434 access_mode="grant",435 obj_type="file",436 reset_perms=False,437 protected=None,438 )439 assert result is True440 # Test has_permissions exact441 result = win_dacl.has_permissions(442 obj_name=str(test_file),443 principal="Backup Operators",444 permissions=["read_data", "write_data"],445 access_mode="grant",446 obj_type="file",447 exact=False,448 )449 assert result is True450def test_has_permissions_missing(test_file):451 result = win_dacl.set_permissions(452 obj_name=str(test_file),453 principal="Backup Operators",454 permissions="read_execute",455 access_mode="grant",456 obj_type="file",457 reset_perms=False,458 protected=None,459 )460 assert result is True461 # Test has_permissions exact462 result = win_dacl.has_permissions(463 obj_name=str(test_file),464 principal="Backup Operators",465 permissions=["read_data", "write_data"],466 access_mode="grant",467 obj_type="file",468 exact=False,469 )470 assert result is False471def test_has_permissions_exact_contains(test_file):472 result = win_dacl.set_permissions(473 obj_name=str(test_file),474 principal="Backup Operators",475 permissions=["read_data", "write_data"],476 access_mode="grant",477 obj_type="file",478 reset_perms=False,479 protected=None,480 )481 assert result is True482 # Test has_permissions exact483 result = win_dacl.has_permissions(484 obj_name=str(test_file),485 principal="Backup Operators",486 permissions=["read_data", "write_data"],487 access_mode="grant",488 obj_type="file",489 exact=True,490 )491 assert result is True492def test_has_permissions_exact_has_extra(test_file):493 result = win_dacl.set_permissions(494 obj_name=str(test_file),495 principal="Backup Operators",496 permissions=["read_data", "write_data", "create_folders"],497 access_mode="grant",498 obj_type="file",499 reset_perms=False,500 protected=None,501 )502 assert result is True503 # Test has_permissions exact504 result = win_dacl.has_permissions(505 obj_name=str(test_file),506 principal="Backup Operators",507 permissions=["read_data", "write_data"],508 access_mode="grant",509 obj_type="file",510 exact=True,511 )512 assert result is False513def test_has_permissions_exact_missing(test_file):514 result = win_dacl.set_permissions(515 obj_name=str(test_file),516 principal="Backup Operators",517 permissions=["read_data", "write_data"],518 access_mode="grant",519 obj_type="file",520 reset_perms=False,521 protected=None,522 )523 assert result is True524 # Test has_permissions exact525 result = win_dacl.has_permissions(526 obj_name=str(test_file),527 principal="Backup Operators",528 permissions=["read_data", "write_data", "create_folders"],529 access_mode="grant",530 obj_type="file",531 exact=True,532 )533 assert result is False534def test_rm_permissions(test_file):535 result = win_dacl.set_permissions(536 obj_name=str(test_file),537 principal="Backup Operators",538 permissions="full_control",539 access_mode="grant",540 obj_type="file",541 reset_perms=False,542 protected=None,543 )544 assert result is True545 expected = {546 "Not Inherited": {547 "Backup Operators": {548 "grant": {549 "applies to": "This folder only",550 "permissions": "Full control",551 }552 }553 }554 }555 result = win_dacl.get_permissions(556 obj_name=str(test_file),557 principal="Backup Operators",558 obj_type="file",559 )560 assert result == expected561 result = win_dacl.rm_permissions(562 obj_name=str(test_file),563 principal="Backup Operators",564 obj_type="file",565 )566 assert result is True567 result = win_dacl.get_permissions(568 obj_name=str(test_file),569 principal="Backup Operators",570 obj_type="file",571 )572 assert result == {}573def test_get_set_inheritance(test_file):574 result = win_dacl.set_inheritance(575 obj_name=str(test_file),576 enabled=True,577 obj_type="file",578 clear=False,579 )580 assert result is True581 result = win_dacl.get_inheritance(obj_name=str(test_file), obj_type="file")582 assert result is True583 result = win_dacl.set_inheritance(584 obj_name=str(test_file),585 enabled=False,586 obj_type="file",587 clear=False,588 )589 assert result is True590 result = win_dacl.get_inheritance(obj_name=str(test_file), obj_type="file")591 assert result is False592def test_copy_security():593 with pytest.helpers.temp_file("source_test.file") as source:594 # Set permissions on Source595 result = win_dacl.set_permissions(596 obj_name=str(source),597 principal="Backup Operators",598 permissions="full_control",599 access_mode="grant",600 obj_type="file",601 reset_perms=False,602 protected=None,603 )604 assert result is True605 # Set owner on Source606 result = win_dacl.set_owner(607 obj_name=str(source), principal="Backup Operators", obj_type="file"608 )609 assert result is True610 # Set group on Source611 result = win_dacl.set_primary_group(612 obj_name=str(source), principal="Backup Operators", obj_type="file"613 )614 assert result is True615 with pytest.helpers.temp_file("target_test.file") as target:616 # Copy security from Source to Target617 result = win_dacl.copy_security(source=str(source), target=str(target))618 assert result is True619 # Verify permissions on Target620 expected = {621 "Not Inherited": {622 "Backup Operators": {623 "grant": {624 "applies to": "This folder only",625 "permissions": "Full control",626 }627 }628 }629 }630 result = win_dacl.get_permissions(631 obj_name=str(target),632 principal="Backup Operators",633 obj_type="file",634 )635 assert result == expected636 # Verify owner on Target637 result = win_dacl.get_owner(obj_name=str(target), obj_type="file")638 assert result == "Backup Operators"639 # Verify group on Target640 result = win_dacl.get_primary_group(obj_name=str(target), obj_type="file")641 assert result == "Backup Operators"642def test_check_perms(test_file):643 result = win_dacl.check_perms(644 obj_name=str(test_file),645 obj_type="file",646 ret={},647 owner="Users",648 grant_perms={"Backup Operators": {"perms": "read"}},649 deny_perms={650 "Backup Operators": {"perms": ["delete"]},651 "NETWORK SERVICE": {652 "perms": [653 "delete",654 "change_permissions",655 "write_attributes",656 "write_data",657 ]658 },659 },660 inheritance=True,661 reset=False,662 )663 expected = {664 "changes": {665 "owner": "Users",666 "grant_perms": {"Backup Operators": {"permissions": "read"}},667 "deny_perms": {668 "Backup Operators": {"permissions": ["delete"]},669 "NETWORK SERVICE": {670 "permissions": [671 "delete",672 "change_permissions",673 "write_attributes",674 "write_data",675 ]676 },677 },678 },679 "comment": "",680 "name": str(test_file),681 "result": True,682 }683 assert result == expected684 expected = {685 "Not Inherited": {686 "Backup Operators": {687 "deny": {688 "applies to": "This folder only",689 "permissions": ["Delete"],690 },691 "grant": {"applies to": "This folder only", "permissions": "Read"},692 }693 }694 }695 result = win_dacl.get_permissions(696 obj_name=str(test_file),697 principal="Backup Operators",698 obj_type="file",699 )700 assert result == expected701 expected = {702 "Not Inherited": {703 "NETWORK SERVICE": {704 "deny": {705 "applies to": "This folder only",706 "permissions": [707 "Change permissions",708 "Create files / write data",709 "Delete",710 "Write attributes",711 ],712 }713 }714 }715 }716 result = win_dacl.get_permissions(717 obj_name=str(test_file),718 principal="NETWORK SERVICE",719 obj_type="file",720 )721 assert result == expected722 result = win_dacl.get_owner(obj_name=str(test_file), obj_type="file")723 assert result == "Users"724def test_check_perms_test_true(test_file):725 with patch.dict(win_dacl.__opts__, {"test": True}):726 result = win_dacl.check_perms(727 obj_name=str(test_file),728 obj_type="file",729 ret=None,730 owner="Users",731 grant_perms={"Backup Operators": {"perms": "read"}},732 deny_perms={733 "NETWORK SERVICE": {734 "perms": ["delete", "set_value", "write_dac", "write_owner"]735 },736 "Backup Operators": {"perms": ["delete"]},737 },738 inheritance=True,739 reset=False,740 )741 expected = {742 "changes": {743 "owner": "Users",744 "grant_perms": {"Backup Operators": {"permissions": "read"}},745 "deny_perms": {746 "Backup Operators": {"permissions": ["delete"]},747 "NETWORK SERVICE": {748 "permissions": [749 "delete",750 "set_value",751 "write_dac",752 "write_owner",753 ]754 },755 },756 },757 "comment": "",758 "name": str(test_file),759 "result": None,760 }761 assert result == expected762 result = win_dacl.get_owner(obj_name=str(test_file), obj_type="file")763 assert result != "Users"764 result = win_dacl.get_permissions(765 obj_name=str(test_file),766 principal="Backup Operators",767 obj_type="file",768 )769 assert result == {}770def test_set_perms(test_file):771 result = win_dacl.set_perms(772 obj_name=str(test_file),773 obj_type="file",774 grant_perms={"Backup Operators": {"perms": "read"}},775 deny_perms={776 "NETWORK SERVICE": {777 "perms": [778 "delete",779 "change_permissions",780 "write_attributes",781 "write_data",782 ]783 }784 },785 inheritance=True,786 reset=False,787 )788 expected = {789 "deny": {790 "NETWORK SERVICE": {791 "perms": [792 "delete",793 "change_permissions",794 "write_attributes",795 "write_data",796 ]797 }798 },799 "grant": {"Backup Operators": {"perms": "read"}},800 }...

Full Screen

Full Screen

monsters.py

Source:monsters.py Github

copy

Full Screen

1from .d20 import roll_dice2import random3class Monster:4 def __init__(self, name=None, level=0, hp=None, ac=None):5 self.name = name.upper() if name else 'UNKNOWN MONSTER'6 self.level = level7 self.hp = hp if hp else self.calc_hit_points()8 self.ac = ac if ac else self.calc_armor_class()9 self.obj_name = 'Monster'10 self.spells = []11 # def attack(self, party):12 # character = random.choice(party)13 # print(f'{self.name} attacks {character.name} and misses.')14 def calc_hit_points(self):15 return roll_dice(f'{self.level}d4+{self.level + 1}')16 def calc_armor_class(self):17 return 10 - random.randint(0, self.level + 2)18 def __str__(self):19 return f'{self.obj_name}(level={self.level}, hp={self.hp}, ac={self.ac})'20 def __repr__(self):21 return f'{self.obj_name}(level={self.level}, hp={self.hp}, ac={self.ac})'22class FloatingCoin(Monster):23 def __init__(self, name='floating coin', level=0, hp=None, ac=None):24 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)25 self.hp = self.calc_hit_points()26 self.obj_name = 'FloatingCoin'27 def calc_hit_points(self):28 return roll_dice(f'{self.level}d6+{self.level + 2}')29class Goblin(Monster):30 def __init__(self, name='goblin', level=0, hp=None, ac=None):31 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)32 self.hp = self.calc_hit_points()33 self.obj_name = 'Goblin'34 def calc_hit_points(self):35 return roll_dice(f'{self.level}d6', find_max=True)36class Orc(Monster):37 def __init__(self, name='orc', level=0, hp=None, ac=None):38 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)39 self.hp = self.calc_hit_points()40 self.obj_name = 'Orc'41 def calc_hit_points(self):42 return roll_dice(f'2d6+{self.level + 2}')43class Skeleton(Monster):44 def __init__(self, name='Skeleton', level=0, hp=None, ac=None):45 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)46 self.hp = self.calc_hit_points()47 self.obj_name = 'Skeleton'48 def calc_hit_points(self):49 return roll_dice(f'2d6+{self.level + 2}')50 def calc_armor_class(self):51 return 2052class Slime(Monster):53 def __init__(self, name='Slime', level=0, hp=None, ac=None):54 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)55 self.hp = 456 self.obj_name = 'Slime'57class Mage(Monster):58 def __init__(self, name='Mage', level=0, hp=None, ac=None):59 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)60 self.hp = 4 * level61 self.obj_name = name62class Kobold(Monster):63 def __init__(self, name='Kobold', level=0, hp=None, ac=None):64 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)65 self.hp = (level * 6) // 266 self.obj_name = name67class GasCloud(Monster):68 def __init__(self, name='GasCloud', level=0, hp=None, ac=None):69 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)70 self.hp = self.calc_hit_points()71 self.obj_name = name72class Zombie(Monster):73 def __init__(self, name='Zombie', level=0, hp=None, ac=None):74 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)75 self.hp = self.calc_hit_points()76 self.obj_name = name77class Dragon(Monster):78 def __init__(self, name='Dragon', level=0, hp=None, ac=None):79 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)80 self.hp = self.calc_hit_points()81 self.obj_name = name82class GiantSpider(Monster):83 def __init__(self, name='GiantSpider', level=0, hp=None, ac=None):84 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)85 self.hp = self.calc_hit_points()86 self.obj_name = name87class Spirit(Monster):88 def __init__(self, name='Spirit', level=0, hp=None, ac=None):89 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)90 self.hp = self.calc_hit_points()91 self.obj_name = name92class RabidDog(Monster):93 def __init__(self, name='RabidDog', level=0, hp=None, ac=None):94 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)95 self.hp = self.calc_hit_points()96 self.obj_name = name97class SoulStealer(Monster):98 def __init__(self, name='SoulStealer', level=0, hp=None, ac=None):99 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)100 self.hp = self.calc_hit_points()101 self.obj_name = name102class EarthGiant(Monster):103 def __init__(self, name='EarthGiant', level=0, hp=None, ac=None):104 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)105 self.hp = self.calc_hit_points()106 self.obj_name = name107class FireGiant(Monster):108 def __init__(self, name='FireGiant', level=0, hp=None, ac=None):109 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)110 self.hp = self.calc_hit_points()111 self.obj_name = name112class AirGiant(Monster):113 def __init__(self, name='AirGiant', level=0, hp=None, ac=None):114 Monster.__init__(self, name=name, level=level, hp=hp, ac=ac)115 self.hp = self.calc_hit_points()116 self.obj_name = name117 self.spells_known()118 self.hp = 100119 self.ac = -10120 def spells_known(self):121 self.spells = ['air blast 0', 'death 0']122 if self.level >= 8:123 self.spells.extend(['s1 8', 's2 8'])124 if self.level >= 9:125 self.spells.append('s1 9')126 127MONSTERS = [128 {'name': 'slime', 'levels': '0123456789', 'obj_name': 'Slime', 'obj': Slime},129 {'name': 'floating coin', 'levels': '0123', 'obj_name': 'FloatingCoin', 'obj': FloatingCoin},130 {'name': 'goblin', 'levels': '01', 'obj_name': 'Goblin', 'obj': Goblin},131 {'name': 'orc', 'levels': '01234', 'obj_name': 'Orc', 'obj': Orc},132 {'name': 'skeleton', 'levels': '01234', 'obj_name': 'Skeleton', 'obj': Skeleton},133 {'name': 'mage', 'levels': '34', 'obj_name': 'Mage', 'obj': Mage},134 {'name': 'kobold', 'levels': '012', 'obj_name': 'Kobold', 'obj': Kobold},135 {'name': 'gas cloud', 'levels': '4', 'obj_name': 'GasCloud', 'obj': GasCloud},136 {'name': 'zombie', 'levels': '012', 'obj_name': 'Zombie', 'obj': Zombie},137 {'name': 'dragon', 'levels': '9', 'obj_name': 'Dragon', 'obj': Dragon},138 {'name': 'giant spider', 'levels': '45', 'obj_name': 'GiantSpider', 'obj': GiantSpider},139 {'name': 'spirit', 'levels': '345', 'obj_name': 'Spirit', 'obj': Spirit},140 {'name': 'rabid dog', 'levels': '234', 'obj_name': 'RabidDog', 'obj': RabidDog},141 {'name': 'soulstealer', 'levels': '01234', 'obj_name': 'SoulStealer', 'obj': SoulStealer},142 {'name': 'earth giant', 'levels': '789', 'obj_name': 'EarthGiant', 'obj': EarthGiant},143 {'name': 'fire giant', 'levels': '789', 'obj_name': 'FireGiant', 'obj': FireGiant},144 {'name': 'air giant', 'levels': '789', 'obj_name': 'AirGiant', 'obj': AirGiant},145]146def summon_monsters(level=0, count=1, name=None):147 eligible = None148 if name:149 for m in MONSTERS:150 if m.get('name') == name:151 eligible = [m]152 break153 if not eligible:154 eligible = [m for m in MONSTERS if '0' in m.get('levels', '0')]155 else:156 eligible = [m for m in MONSTERS if str(level) in m.get('levels', '0')]157 monster = random.choice(eligible)158 summoned = [monster.get('obj', Slime)(name=monster.get('obj_name', 'Slime'), level=level) for _ in range(count)]...

Full Screen

Full Screen

gen_bboxes.py

Source:gen_bboxes.py Github

copy

Full Screen

1"""2 A labl annotation looks like:3 width | height | nBoxes | x0 | y0 | w0 | h0 | x1 | y1 | w1 | h1 |...| label0 | label1 ...4 A json annotation looks like:5{6 "im_w":<INT>,7 "im_h":<INT>,8 "objects":[9 {10 "desc":<STR>,11 "box_xywh":[<INT>, <INT>, <INT>, <INT>]12 },13 {14 <OBJ_2>15 },16 ...17 {18 <OBJ_n>19 }20 ]21}22 returns: dict of object names and their GT bboxes23 when multiple objects of the same desc are present, they are 24 auto-indexed with a '__<INT>' suffix on the object desc:25 person__1, person__2, etc.26"""27import numpy as np28"""29import json as j30import gen_bboxes as g31prs_j = g.get_bbox_fn('person_wearing_glasses', 'json')32j_file = open('/home/econser/research/irsg_psu_pdx/data/PersonWearingGlasses/PersonWearingGlassesTrain/person-wearing-glasses1.json', 'rb')33j_obj = j.load(j_file)34j_out = prs_j(j_obj)35prs_l = g.get_bbox_fn('person_wearing_glasses', 'labl')36l_file = open('/home/econser/research/irsg_psu_pdx/data/PersonWearingGlasses/PersonWearingGlassesTrain/person-wearing-glasses1.labl', 'rb')37l_obj = l_file.readlines()[0]38l_out = prs_l(l_obj)39"""40#===============================================================================41def get_bbox_fn(model_name, anno_type):42 parse_fn_dict = {43 'labl' : labl_parse_fn,44 'json' : json_parse_fn45 }46 anno_map_fn_dict = {47 'dog_walking' : dw_anno_map,48 'ping_pong' : pp_anno_map,49 'handshake' : hs_anno_map,50 'leading_horse' : lh_anno_map,51 'person_wearing_glasses' : pwg_anno_map,52 'full_minivg' : mvg_anno_map53 }54 parse_fn = parse_fn_dict.get(anno_type)55 anno_map_fn = anno_map_fn_dict.get(model_name)56 57 if model_name == 'full_minivg':58 return (lambda anno: minivg(anno_map_fn, parse_fn, anno))59 60 return (lambda anno: generic_bbox_fn(anno_map_fn, parse_fn, anno))61def minivg(map_fn, parse_fn, annotation):62 objects, bboxes = parse_fn(annotation)63 64 # check to see if we need to pair up objects65 do_pairing = False66 for obj_name in objects:67 if '_' in obj_name:68 do_pairing = True69 break70 71 if do_pairing:72 # we're assuming 2 types of objects with '<obj_name>__<index>' format73 num_pairs = len(objects) / 274 # split the objects into obj_name, ix, bbox tuples75 obj_names = []76 sit_ixs = []77 bbox_list = []78 for anno_ix, obj in enumerate(objects):79 name, ix = obj.split('_')80 ix = int(ix)81 obj_names.append(name.lower())82 sit_ixs.append(ix)83 bbox_list.append(bboxes[anno_ix])84 sit_ixs = np.array(sit_ixs)85 86 # now pair up the rel pairs87 obj_dicts = []88 for pair_ix in range(num_pairs):89 ref_ix = np.where(sit_ixs-1 == pair_ix)[0]90 obj_dict = {}91 obj_dict[obj_names[ref_ix[0]]] = bbox_list[ref_ix[0]]92 obj_dict[obj_names[ref_ix[1]]] = bbox_list[ref_ix[1]]93 94 obj_dicts.append(obj_dict)95 96 return obj_dicts97 else:98 for obj_ix, obj_name in enumerate(objects):99 objects[obj_ix] = map_fn(obj_name)100 objects = deconflict(objects)101 102 # zip class names and bboxes103 obj_dict = dict(zip(objects, bboxes))104 return [obj_dict]105def generic_bbox_fn(map_fn, parse_fn, annotation):106 objects, bboxes = parse_fn(annotation)107 108 # convert annotations to class names109 for obj_ix, obj_name in enumerate(objects):110 objects[obj_ix] = map_fn(obj_name)111 objects = deconflict(objects)112 113 # zip class names and bboxes114 obj_dict = dict(zip(objects, bboxes))115 return obj_dict116def deconflict(name_list):117 cpy = list(name_list)118 119 ready = []120 for ix in range(0, len(name_list)):121 ready.append(False)122 123 for i, i_name in enumerate(cpy):124 if ready[i]:125 continue126 127 for j, j_name in enumerate(cpy[i+1:]):128 if j_name == i_name:129 # there's a match, dedupe130 suffix_num = 1131 for k in range(i, len(cpy)):132 k_name = name_list[k]133 if k_name == i_name:134 cpy[k] = '{}__{}'.format(i_name, suffix_num)135 ready[k] = True136 suffix_num += 1137 ready[i] = True138 139 return cpy140#-------------------------------------------------------------------------------141def labl_parse_fn(annotation):142 tokens = annotation.split('|')143 n_boxes = int(tokens[2])144 n_coords = len(tokens) - n_boxes145 coords = tokens[3 : n_coords]146 147 objects = tokens[-n_boxes:]148 bboxes = []149 150 for obj_ix in range(0, len(objects)):151 start_ix = obj_ix * 4152 end_ix = start_ix + 4153 154 coord_slice = coords[start_ix : end_ix]155 bbox = np.array(coord_slice, dtype=np.int)156 bboxes.append(bbox)157 158 return objects, bboxes159def json_parse_fn(annotation):160 names = []161 bboxes = []162 for o in annotation['objects']:163 names.append(o['desc'])164 bboxes.append(np.array(o['box_xywh'], dtype=np.int))165 return names, bboxes166#-------------------------------------------------------------------------------167def generic_anno_map(obj_name):168 return obj_name.split(' ')[0]169def mvg_anno_map(obj_name):170 obj = obj_name.split(' ')[0]171 obj = obj.split('_')[0]172 # check for multi173 return obj.lower()174def dw_anno_map(obj_name):175 if obj_name.startswith('dog-walker'):176 return 'dog_walker'177 elif obj_name.startswith('dog'):178 return 'dog'179 elif obj_name.startswith('leash'):180 return 'leash'181 else:182 return obj_name.split(' ')[0]183def pp_anno_map(obj_name):184 if obj_name.startswith('player-'):185 return 'player'186 elif obj_name.startswith('net'):187 return 'net'188 elif obj_name.startswith('table'):189 return 'table'190 else:191 return obj_name.split(' ')[0]192def hs_anno_map(obj_name):193 if obj_name.startswith('person-'):194 return 'person'195 elif obj_name.startswith('handshake'):196 return 'handshake'197 else:198 return obj_name.split(' ')[0]199def lh_anno_map(obj_name):200 if obj_name.startswith('horse-leader'):201 return 'horse-leader'202 elif obj_name.startswith('horse'):203 return 'horse'204 elif obj_name.startswith('lead'):205 return 'lead'206 else:207 return obj_name.split(' ')[0]208def pwg_anno_map(obj_name):209 if obj_name.startswith('person'):210 return 'person'211 elif obj_name.startswith('glasses'):212 return 'glasses'213 else:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful