How to use test_exception method in green

Best Python code snippet using green

testcases.py

Source:testcases.py Github

copy

Full Screen

1""" """2from collections import defaultdict3from time import perf_counter4import traceback5from typing import List, Callable6import adsk.fusion, adsk.core7from .. import fusion_addin_framework as faf8def execute_cases(cases: List[Callable]):9 """Executes the passed functions in a controlled environment and logs some10 data about their axacution.11 Args:12 cases (List[Callable]): A list of the testfuctions to execute.13 Returns:14 dict: A dictionairy with the test resulte mapped to the function name.15 list: A list of addins which where created durin the execution of the tests.16 """17 results = defaultdict(dict)18 addins = []19 for case in cases:20 try:21 print(f"{f' {case.__name__} ':{'#'}^{60}}")22 start = perf_counter()23 addin = case()24 addins.append(addin)25 results[case.__name__]["elapsed_time"] = perf_counter() - start26 results[case.__name__]["passed"] = True27 except:28 results[case.__name__]["elapsed_time"] = -129 results[case.__name__]["passed"] = False30 print(traceback.format_exc())31 return results, addins32 ### Testcases ###33def test_hello_world_button_normal():34 try:35 addin = faf.FusionAddin()36 ws = faf.Workspace(addin)37 tab = faf.Tab(ws)38 panel = faf.Panel(tab)39 button = faf.Control(panel)40 cmd = faf.AddinCommand(41 button,42 onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(43 "hello world"44 ),45 )46 except Exception as test_exception:47 addin.stop()48 raise test_exception49 return addin50def test_hello_world_button_dotted():51 try:52 addin = faf.FusionAddin()53 cmd = (54 addin.workspace()55 .tab()56 .panel()57 .control()58 .addinCommand(59 onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(60 "hello world"61 ),62 )63 )64 except Exception as test_exception:65 addin.stop()66 raise test_exception67 return addin68def test_hello_world_button_defaults():69 try:70 cmd = faf.AddinCommand(71 onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(72 "hello world"73 )74 )75 except Exception as test_exception:76 cmd.addin.stop()77 raise test_exception78 return cmd.addin79def test_checkbox_normal():80 try:81 addin = faf.FusionAddin()82 ws = faf.Workspace(addin)83 tab = faf.Tab(ws)84 panel = faf.Panel(tab)85 checkbox = faf.Control(panel, controlType="checkbox")86 cmd = faf.AddinCommand(87 checkbox,88 onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(89 "hello world"90 ),91 )92 except Exception as test_exception:93 addin.stop()94 raise test_exception95 return addin96def test_checkbox_dotted():97 try:98 addin = faf.FusionAddin()99 cmd = (100 addin.workspace()101 .tab()102 .panel()103 .control(controlType="checkbox")104 .addinCommand(105 onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(106 "hello world"107 ),108 )109 )110 except Exception as test_exception:111 addin.stop()112 raise test_exception113 return addin114def test_checkbox_defaults():115 try:116 checkbox = faf.Control(controlType="checkbox")117 cmd = faf.AddinCommand(118 checkbox,119 onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(120 "hello world"121 ),122 )123 except Exception as test_exception:124 checkbox.addin.stop()125 raise test_exception126 return checkbox.addin127# def test_list_normal():128# try:129# addin = faf.FusionAddin()130# ws = faf.Workspace(addin)131# tab = faf.Tab(ws)132# panel = faf.Panel(tab)133# checkbox = faf.Control(panel, controlType="list")134# cmd = faf.AddinCommand(135# checkbox,136# onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(137# "hello world"138# ),139# )140# except Exception as test_exception:141# addin.stop()142# raise test_exception143# return addin144# def test_list_dotted():145# try:146# addin = faf.FusionAddin()147# cmd = (148# addin.workspace()149# .tab()150# .panel()151# .control(controlType="list")152# .addinCommand(153# onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(154# "hello world"155# ),156# )157# )158# except Exception as test_exception:159# addin.stop()160# raise test_exception161# return addin162# def test_list_defaults():163# try:164# list_ctrl = faf.Control(controlType="list")165# cmd = faf.AddinCommand(166# list_ctrl,167# onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(168# "hello world"169# ),170# )171# except Exception as test_exception:172# list_ctrl.addin.stop()173# raise test_exception174# return list_ctrl.addin175def test_standard_attrs_button():176 try:177 cmd = (178 faf.FusionAddin(debugToUi=True)179 .workspace(180 id="FusionSolidEnvironment",181 name="random",182 productType="DesignProductType",183 resourceFolder="lightbulb",184 toolClipFilename="lightbulb",185 tooltip="",186 tooltipDescription="",187 )188 .tab(189 id="default",190 name="random",191 )192 .panel(193 id="default",194 name="random",195 positionID="",196 isBefore=True,197 )198 .control(199 controlType="button",200 isVisible=True,201 isPromoted=True,202 isPromotedByDefault=True,203 positionID="",204 isBefore=True,205 )206 .addinCommand(207 id="random",208 name="random",209 resourceFolder="lightbulb",210 tooltip="",211 toolClipFileName=None,212 isEnabled=True,213 isVisible=True,214 isChecked=True,215 onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(216 "hello world"217 ),218 )219 )220 except Exception as test_exception:221 cmd.addin.stop()222 raise test_exception223 return cmd.addin224def test_very_custom_button():225 try:226 addin = faf.FusionAddin(debugToUi=True)227 ws = faf.Workspace(228 addin,229 id="FusionSolidEnvironment",230 name="my test name",231 productType="DesignProductType",232 resourceFolder=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/test_images/one",233 toolClipFilename=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one/32x32.png",234 tooltip="my test tooltip",235 tooltipDescription="my test tooltip description",236 )237 tab = faf.Tab(238 ws,239 id="my test tab id",240 name="my name",241 )242 panel = faf.Panel(243 tab,244 id="mytestpanelid",245 name="my panels name",246 positionID="",247 isBefore=True,248 )249 ctrl = faf.Control(250 panel,251 controlType="button",252 isVisible=True,253 isPromoted=True,254 isPromotedByDefault=True,255 positionID="",256 isBefore=True,257 )258 cmd = faf.AddinCommand(259 ctrl,260 id="mycustomcmdid",261 name="ma command",262 resourceFolder=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one",263 tooltip="my custom tooltip",264 toolClipFileName=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one/32x32.png",265 isEnabled=True,266 isVisible=True,267 isChecked=True,268 onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(269 "hello world"270 ),271 )272 except Exception as test_exception:273 addin.stop()274 raise test_exception275 return addin276def test_very_custom_checkbox():277 try:278 addin = faf.FusionAddin(debugToUi=True)279 ws = faf.Workspace(280 addin,281 id="FusionSolidEnvironment",282 name="my test name",283 productType="DesignProductType",284 resourceFolder=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one",285 toolClipFilename=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one/32x32.png",286 tooltip="my test tooltip",287 tooltipDescription="my test tooltip description",288 )289 tab = faf.Tab(290 ws,291 id="my test tab id",292 name="my name",293 )294 panel = faf.Panel(295 tab,296 id="mytestpanelid",297 name="my panels name",298 positionID="",299 isBefore=True,300 )301 ctrl = faf.Control(302 panel,303 controlType="checkbox",304 isVisible=True,305 isPromoted=False,306 isPromotedByDefault=False,307 positionID="",308 isBefore=True,309 )310 cmd = faf.AddinCommand(311 ctrl,312 id="mycustomcheckboxcmdid",313 name="ma command",314 resourceFolder=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one",315 tooltip="my custom tooltip",316 toolClipFileName=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one/32x32.png",317 isEnabled=True,318 isVisible=True,319 isChecked=True,320 onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(321 "hello world"322 ),323 )324 except Exception as test_exception:325 addin.stop()326 raise test_exception327 return addin328# def test_very_custom_list():329# try:330# addin = faf.FusionAddin(debugToUi=True)331# ws = faf.Workspace(332# addin,333# id="FusionSolidEnvironment",334# name="my test name",335# productType="DesignProductType",336# resourceFolder=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one",337# toolClipFilename=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one/32x32.png",338# tooltip="my test tooltip",339# tooltipDescription="my test tooltip description",340# )341# tab = faf.Tab(342# ws,343# id="my test tab id",344# name="my name",345# )346# panel = faf.Panel(347# tab,348# id="mytestpanelid",349# name="my panels name",350# positionID="",351# isBefore=True,352# )353# ctrl = faf.Control(354# panel,355# controlType="list",356# isVisible=True,357# isPromoted=True,358# isPromotedByDefault=True,359# positionID="",360# isBefore=True,361# )362# cmd = faf.AddinCommand(363# ctrl,364# id="mycustomlistcmdid",365# name="ma command",366# resourceFolder=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one",367# tooltip="my custom tooltip",368# toolClipFileName=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one/32x32.png",369# isEnabled=True,370# isVisible=True,371# isChecked=True,372# onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(373# "hello world"374# ),375# )376# except Exception as test_exception:377# addin.stop()378# raise test_exception379# return addin380def test_addin_properties():381 try:382 addin = faf.FusionAddin(debugToUi=False)383 assert addin.debugToUi == False384 addin.debugToUi = True385 assert addin.debugToUi == True386 assert addin.uiLevel == 0387 except Exception as test_exception:388 addin.stop()389 raise test_exception390 return addin391def test_workspace_properties():392 try:393 addin = faf.FusionAddin()394 ws = faf.Workspace(395 addin,396 id="FusionSolidEnvironment", # TODO test custom ws with posix path397 name="my test name",398 productType="DesignProductType",399 resourceFolder=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one",400 toolClipFilename=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one/32x32.png",401 tooltip="my test tooltip",402 tooltipDescription="my test tooltip description",403 )404 print(ws.parent)405 print(ws.addin)406 assert ws.uiLevel == 1407 assert ws.id == "FusionSolidEnvironment"408 print(ws.isActive)409 assert ws.isNative == True410 assert ws.isValid == True411 print(ws.name)412 print(ws.objectType)413 assert ws.productType == "DesignProductType"414 print(ws.toolbarPanels)415 print(ws.toolbarTabs)416 print(ws.resourceFolder)417 print(ws.toolClipFilename)418 print(ws.tooltip)419 print(ws.tooltipDescription)420 # no setable attributes421 print(ws.activate)422 print(ws.deleteMe)423 print(ws.classType())424 except Exception as test_exception:425 addin.stop()426 raise test_exception427 return addin428def test_tab_properties():429 try:430 addin = faf.FusionAddin()431 ws = faf.Workspace(addin)432 tab = faf.Tab(433 ws,434 id="test_tab_properties_tab_id",435 name="my name",436 )437 print(tab.parent)438 print(tab.addin)439 assert tab.uiLevel == 2440 assert tab.id == "test_tab_properties_tab_id"441 print(tab.index)442 print(tab.isActive)443 assert tab.isNative == False444 assert tab.isValid == True445 print(tab.isVisible)446 assert tab.name == "my name"447 print(tab.objectType)448 print(tab.parentUserInterface)449 assert tab.productType == "DesignProductType"450 print(tab.toolbarPanels)451 # no setable attributes452 print(tab.activate)453 print(tab.deleteMe)454 print(tab.classType())455 except Exception as test_exception:456 addin.stop()457 raise test_exception458 return addin459def test_panel_properties():460 try:461 addin = faf.FusionAddin()462 ws = faf.Workspace(addin)463 tab = faf.Tab(ws)464 panel = faf.Panel(465 tab,466 id="test_panel_properties_panel_id",467 name="my panels name",468 positionID="",469 isBefore=True,470 )471 print(panel.parent)472 print(panel.addin)473 assert panel.uiLevel == 3474 print(panel.controls)475 assert panel.id == "test_panel_properties_panel_id"476 assert panel.isValid == True477 print(panel.isVisible)478 assert panel.name == "my panels name"479 print(panel.objectType)480 print(panel.parentUserInterface)481 assert panel.productType == "DesignProductType"482 print(panel.promotedControls)483 print(panel.relatedWorkspaces)484 # no setable attributes485 print(panel.classType())486 print(panel.deleteMe)487 print(panel.indexWithinTab)488 except Exception as test_exception:489 addin.stop()490 raise test_exception491 return addin492def test_button_properties():493 try:494 addin = faf.FusionAddin()495 ws = faf.Workspace(addin)496 tab = faf.Tab(ws)497 panel = faf.Panel(tab)498 button = faf.Control(499 panel,500 controlType="button",501 isVisible=True,502 isPromoted=True,503 isPromotedByDefault=True,504 positionID="",505 isBefore=True,506 )507 print(button.parent)508 print(button.addin)509 assert button.uiLevel == 4510 print(button.commandDefinition)511 print(button.id)512 assert button.isPromoted == True513 button.isPromoted = False514 assert button.isPromoted == False515 assert button.isPromotedByDefault == True516 button.isPromotedByDefault = False517 assert button.isPromotedByDefault == False518 assert button.isValid == True519 print(button.isVisible)520 print(button.objectType)521 print(button.parent)522 print(button.classType())523 print(button.deleteMe)524 assert (525 button.commandDefinition.controlDefinition.objectType526 == adsk.core.ButtonControlDefinition.classType()527 )528 except Exception as test_exception:529 addin.stop()530 raise test_exception531 return addin532def test_checkbox_properties():533 try:534 addin = faf.FusionAddin()535 ws = faf.Workspace(addin)536 tab = faf.Tab(ws)537 panel = faf.Panel(tab)538 checkbox = faf.Control(539 panel,540 controlType="checkbox",541 isVisible=True,542 isPromoted=True,543 isPromotedByDefault=True,544 positionID="",545 isBefore=True,546 )547 print(checkbox.parent)548 print(checkbox.addin)549 assert checkbox.uiLevel == 4550 print(checkbox.commandDefinition)551 print(checkbox.id)552 assert checkbox.isPromoted == True553 checkbox.isPromoted = False554 assert checkbox.isPromoted == False555 assert checkbox.isPromotedByDefault == True556 checkbox.isPromotedByDefault = False557 assert checkbox.isPromotedByDefault == False558 assert checkbox.isValid == True559 print(checkbox.isVisible)560 print(checkbox.objectType)561 print(checkbox.parent)562 print(checkbox.classType())563 print(checkbox.deleteMe)564 assert (565 checkbox.commandDefinition.controlDefinition.objectType566 == adsk.core.CheckBoxControlDefinition.classType()567 )568 except Exception as test_exception:569 addin.stop()570 raise test_exception571 return addin572# def test_list_properties():573# try:574# addin = faf.FusionAddin()575# ws = faf.Workspace(addin)576# tab = faf.Tab(ws)577# panel = faf.Panel(tab)578# list_ctrl = faf.Control(579# panel,580# controlType="list",581# isVisible=True,582# isPromoted=True,583# isPromotedByDefault=True,584# positionID="",585# isBefore=True,586# )587# print(list_ctrl.parent)588# print(list_ctrl.addin)589# assert list_ctrl.uiLevel == 4590# print(list_ctrl.commandDefinition)591# print(list_ctrl.id)592# assert list_ctrl.isPromoted == True593# list_ctrl.isPromoted = False594# assert list_ctrl.isPromoted == False595# assert list_ctrl.isPromotedByDefault == True596# list_ctrl.isPromotedByDefault = False597# assert list_ctrl.isPromotedByDefault == False598# assert list_ctrl.isValid == True599# print(list_ctrl.isVisible)600# print(list_ctrl.objectType)601# print(list_ctrl.parent)602# print(list_ctrl.classType())603# print(list_ctrl.deleteMe)604# assert (605# list_ctrl.commandDefinition.controlDefinition.objectType606# == adsk.core.ListControlDefinition.classType()607# )608# except Exception as test_exception:609# addin.stop()610# raise test_exception611# return addin612def test_button_command_properties():613 try:614 addin = faf.FusionAddin()615 ws = faf.Workspace(addin)616 tab = faf.Tab(ws)617 panel = faf.Panel(tab)618 button = faf.Control(panel)619 cmd = faf.AddinCommand(620 button,621 id="test_button_command_properties_cmd_id",622 name="ma command",623 resourceFolder=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one",624 tooltip="my custom tooltip",625 toolClipFileName=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one/32x32.png",626 isEnabled=True,627 isVisible=True,628 isChecked=True,629 onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(630 "hello world"631 ),632 )633 print(cmd.parent)634 print(cmd.addin)635 assert cmd.uiLevel == 5636 # controlDefinition attributes637 print(cmd.controlDefinition)638 assert cmd.isEnabled == True639 cmd.isEnabled = False640 assert cmd.isEnabled == False641 assert cmd.isValid == True642 assert cmd.isVisible == True643 cmd.isVisible = False644 assert cmd.isVisible == False645 cmd.isVisible = True646 # assert cmd.name == "ma command"647 # cmd.name = "2"648 # assert cmd.name == "2"649 # print(cmd.objectType)650 # commandDefinition attributes651 assert cmd.id == "test_button_command_properties_cmd_id"652 assert cmd.isNative == False653 assert cmd.isValid == True654 assert cmd.name == "ma command"655 cmd.name = "2"656 assert cmd.name == "2"657 print(cmd.objectType)658 assert (659 cmd.resourceFolder660 == r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one"661 )662 cmd.resourceFolder = r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/two"663 assert (664 cmd.resourceFolder665 == r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/two"666 )667 assert (668 cmd.toolClipFilename669 == r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one/32x32.png"670 )671 cmd.toolClipFilename = r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/two/32x32.png"672 assert (673 cmd.toolClipFilename674 == r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/two/32x32.png"675 )676 # accessing the tooltip returns empty string. This is an error in the API.677 # print(cmd.tooltip)678 # assert cmd.tooltip == "my custom tooltip"679 cmd.tooltip = "my tooltip 2"680 # assert cmd.tooltip == "my tooltip 2"681 print(cmd.classType())682 print(cmd.deleteMe)683 print(cmd.execute)684 except Exception as test_exception:685 addin.stop()686 raise test_exception687 return addin688def test_checkbox_command_properties():689 try:690 addin = faf.FusionAddin()691 ws = faf.Workspace(addin)692 tab = faf.Tab(ws)693 panel = faf.Panel(tab)694 checkbox = faf.Control(panel, controlType="checkbox")695 cmd = faf.AddinCommand(696 checkbox,697 id="test_checkbox_command_properties_cmd_id",698 name="ma command",699 resourceFolder=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one",700 tooltip="my custom tooltip",701 toolClipFileName=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one/32x32.png",702 isEnabled=True,703 isVisible=True,704 isChecked=True,705 onExecute=lambda command_event_args: adsk.core.Application.get().userInterface.messageBox(706 "hello world"707 ),708 )709 print(cmd.parent)710 print(cmd.addin)711 assert cmd.uiLevel == 5712 # controlDefinition attributes713 print(cmd.controlDefinition)714 assert cmd.isEnabled == True715 cmd.isEnabled = False716 assert cmd.isEnabled == False717 assert cmd.isChecked == True718 cmd.isChecked = False719 assert cmd.isChecked == False720 assert cmd.isValid == True721 assert cmd.isVisible == True722 cmd.isVisible = False723 assert cmd.isVisible == False724 cmd.isVisible = True725 # assert cmd.name == "ma command"726 # cmd.name = "2"727 # assert cmd.name == "2"728 # print(cmd.objectType)729 # commandDefinition attributes730 assert cmd.id == "test_checkbox_command_properties_cmd_id"731 assert cmd.isNative == False732 assert cmd.isValid == True733 assert cmd.name == "ma command"734 cmd.name = "2"735 assert cmd.name == "2"736 print(cmd.objectType)737 assert (738 cmd.resourceFolder739 == r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one"740 )741 cmd.resourceFolder = r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/two"742 assert (743 cmd.resourceFolder744 == r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/two"745 )746 assert (747 cmd.toolClipFilename748 == r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one/32x32.png"749 )750 cmd.toolClipFilename = r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/two/32x32.png"751 assert (752 cmd.toolClipFilename753 == r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/two/32x32.png"754 )755 # accessing the tooltip returns empty string. This is an error in the API.756 # print(cmd.tooltip)757 # assert cmd.tooltip == "my custom tooltip"758 cmd.tooltip = "my tooltip 2"759 # assert cmd.tooltip == "my tooltip 2"760 print(cmd.classType())761 print(cmd.deleteMe)762 print(cmd.execute)763 except Exception as test_exception:764 addin.stop()765 raise test_exception766 return addin767def test_all_on_handlers_buttton():768 try:769 cmd = faf.AddinCommand(770 onCommandCreated=lambda args: args.command.commandInputs.addBoolValueInput(771 "customboolvalueinputid", "bool", False772 ),773 onActivate=lambda args: print("onActivate", args),774 onDeactivate=lambda args: print("onDeactivate", args),775 onDestroy=lambda args: print("onDestroy", args),776 onExecute=lambda args: print("onExecute", args),777 onExecutePreview=lambda args: print("onExecutePreview", args),778 onInputChanged=lambda args: print("onInputChanged", args),779 onKeyDown=lambda args: print("onKayDown", args),780 onKeyUp=lambda args: print("onKayUp", args),781 onMouseClick=lambda args: print("onMouseClick", args),782 onMouseDoubleClick=lambda args: print("onMouseDoubleClick", args),783 onMouseDown=lambda args: print("onMouseDown", args),784 onMouseDrag=lambda args: print("onMouseDrag", args),785 onMouseDragBegin=lambda args: print("onMouseDrgaBegin", args),786 onMouseDragEnd=lambda args: print("onMouseDragEnd", args),787 onMouseUp=lambda args: print("onMouseUp", args),788 onMouseWheel=lambda args: print("onMouseWheel", args),789 # onMouseMove=lambda args: print("onMouseMove", args),790 onPreSelect=lambda args: print("onPreSelect", args),791 onPreSelectEnd=lambda args: print("onPreSelectEnd", args),792 onPreSelectMouseMove=lambda args: print("onPreSelectMouseMove", args),793 onSelect=lambda args: print("onSelect", args),794 onUnselect=lambda args: print("onUnselect", args),795 onValidateInputs=lambda args: print("onValidateInputs", args),796 )797 except Exception as test_exception:798 cmd.addin.stop()799 raise test_exception800 return cmd.addin801def test_all_on_handlers_checkbox():802 try:803 checkbox = faf.Control(controlType="checkbox")804 cmd = faf.AddinCommand(805 checkbox,806 onCommandCreated=lambda args: args.command.commandInputs.addBoolValueInput(807 "customboolvalueinputid", "bool", False808 ),809 onActivate=lambda args: print("onActivate", args),810 onDeactivate=lambda args: print("onDeactivate", args),811 onDestroy=lambda args: print("onDestroy", args),812 onExecute=lambda args: print("onExecute", args),813 onExecutePreview=lambda args: print("onExecutePreview", args),814 onInputChanged=lambda args: print("onInputChanged", args),815 onKeyDown=lambda args: print("onKayDown", args),816 onKeyUp=lambda args: print("onKayUp", args),817 onMouseClick=lambda args: print("onMouseClick", args),818 onMouseDoubleClick=lambda args: print("onMouseDoubleClick", args),819 onMouseDown=lambda args: print("onMouseDown", args),820 onMouseDrag=lambda args: print("onMouseDrag", args),821 onMouseDragBegin=lambda args: print("onMouseDrgaBegin", args),822 onMouseDragEnd=lambda args: print("onMouseDragEnd", args),823 onMouseUp=lambda args: print("onMouseUp", args),824 onMouseWheel=lambda args: print("onMouseWheel", args),825 # onMouseMove=lambda args: print("onMouseMove", args),826 onPreSelect=lambda args: print("onPreSelect", args),827 onPreSelectEnd=lambda args: print("onPreSelectEnd", args),828 onPreSelectMouseMove=lambda args: print("onPreSelectMouseMove", args),829 onSelect=lambda args: print("onSelect", args),830 onUnselect=lambda args: print("onUnselect", args),831 onValidateInputs=lambda args: print("onValidateInputs", args),832 )833 except Exception as test_exception:834 cmd.addin.stop()835 raise test_exception836 return cmd.addin837def test_all_handlers_buttton():838 try:839 cmd = faf.AddinCommand(840 commandCreated=lambda args: args.command.commandInputs.addBoolValueInput(841 "customboolvalueinputid", "bool", False842 ),843 activate=lambda args: print("onActivate", args),844 deactivate=lambda args: print("onDeactivate", args),845 destroy=lambda args: print("onDestroy", args),846 execute=lambda args: print("onExecute", args),847 executePreview=lambda args: print("onExecutePreview", args),848 inputChanged=lambda args: print("onInputChanged", args),849 keyDown=lambda args: print("onKayDown", args),850 keyUp=lambda args: print("onKayUp", args),851 mouseClick=lambda args: print("onMouseClick", args),852 mouseDoubleClick=lambda args: print("onMouseDoubleClick", args),853 mouseDown=lambda args: print("onMouseDown", args),854 mouseDrag=lambda args: print("onMouseDrag", args),855 mouseDragBegin=lambda args: print("onMouseDrgaBegin", args),856 mouseDragEnd=lambda args: print("onMouseDragEnd", args),857 mouseUp=lambda args: print("onMouseUp", args),858 mouseWheel=lambda args: print("onMouseWheel", args),859 # mouseMove=lambda args: print("onMouseMove", args),860 preSelect=lambda args: print("onPreSelect", args),861 preSelectEnd=lambda args: print("onPreSelectEnd", args),862 preSelectMouseMove=lambda args: print("onPreSelectMouseMove", args),863 select=lambda args: print("onSelect", args),864 unselect=lambda args: print("onUnselect", args),865 validateInputs=lambda args: print("onValidateInputs", args),866 )867 except Exception as test_exception:868 cmd.addin.stop()869 raise test_exception870 return cmd.addin871def test_error_handlers_passed_buttton():872 try:873 cmd = faf.AddinCommand(874 execute=lambda args: print("onExecute", args),875 onExecute=lambda args: print("onExecute DOUBLE", args),876 asdasd=lambda args: print("error"),877 )878 except Exception as test_exception:879 cmd.addin.stop()880 raise test_exception881 return cmd.addin882def test_error_in_handler():883 def raise_error(args):884 print("start")885 raise ValueError886 print("end")887 try:888 cmd = faf.AddinCommand(889 execute=raise_error, # print("onExecute", args),890 )891 cmd.addin.debugToUi = False892 assert cmd.addin.debugToUi == False893 except Exception as test_exception:894 cmd.addin.stop()895 raise test_exception896 return cmd.addin897def test_multiple_controls():898 try:899 addin = faf.FusionAddin()900 ws = faf.Workspace(addin)901 tab = faf.Tab(ws)902 panel = faf.Panel(tab)903 button_1 = faf.Control(panel)904 # two buttons in one panel is not allowed905 # button_2 = faf.Control(panel)906 panel_2 = faf.Panel(tab, "random")907 button_3 = faf.Control(panel_2)908 cmd = faf.AddinCommand([button_1, button_3])909 tab_2 = faf.Tab(ws, "random")910 panel_3 = faf.Panel(tab_2)911 button_5 = faf.Control(panel_3)912 cmd.addParentControl(button_5)913 except Exception as test_exception:914 addin.stop()915 raise test_exception916 return addin917def test_multiple_controls_2():918 try:919 addin = faf.FusionAddin()920 ws = faf.Workspace(addin)921 tab = faf.Tab(ws)922 panel = faf.Panel(tab)923 button_1 = faf.Control(panel)924 # button_2 = faf.Control(panel)925 panel_2 = faf.Panel(tab, "random")926 button_3 = faf.Control(panel_2)927 # button_4 = faf.control(panel_2)928 cmd = faf.AddinCommand(button_1)929 # cmd.addParentControl(button_2)930 cmd.addParentControl(button_3)931 # cmd.addParentControl(button_4)932 tab_2 = faf.Tab(ws, "random")933 panel_3 = faf.Panel(tab_2)934 button_5 = faf.Control(panel_3)935 cmd.addParentControl(button_5)936 except Exception as test_exception:937 addin.stop()938 raise test_exception939 return addin940def test_multiple_controls_3():941 try:942 addin = faf.FusionAddin()943 ws = faf.Workspace(addin)944 tab = faf.Tab(ws)945 panel = faf.Panel(tab)946 button_1 = faf.Control(panel)947 panel_2 = faf.Panel(tab, "random")948 button_3 = faf.Control(panel_2)949 cmd = faf.AddinCommand([button_1])950 cmd.addParentControl(button_3)951 tab_2 = faf.Tab(ws, "random")952 panel_3 = faf.Panel(tab_2)953 button_5 = faf.Control(panel_3)954 cmd.addParentControl(button_5)955 except Exception as test_exception:956 addin.stop()957 raise test_exception958 return addin959def test_multiple_controls_different_type():960 try:961 addin = faf.FusionAddin()962 ws = faf.Workspace(addin)963 tab = faf.Tab(ws)964 panel = faf.Panel(tab)965 checkbox = faf.Control(panel, controlType="checkbox")966 panel_2 = faf.Panel(tab, "random")967 button_3 = faf.Control(panel_2)968 cmd = faf.AddinCommand([checkbox, button_3])969 except Exception as test_exception:970 addin.stop()971 raise test_exception972 return addin973def test_dropdown_normal():974 try:975 addin = faf.FusionAddin()976 ws = faf.Workspace(addin)977 tab = faf.Tab(ws, id="random")978 panel = faf.Panel(tab)979 dd = faf.Dropdown(panel)980 ctrl = faf.Control(dd, isPromoted=False, isPromotedByDefault=False)981 ctrl_2 = faf.Control(dd)982 cmd = faf.AddinCommand(ctrl)983 except Exception as test_exception:984 addin.stop()985 raise test_exception986 return addin987def test_dropdown_default():988 try:989 dd = faf.Dropdown()990 ctrl = faf.Control(dd)991 except Exception as test_exception:992 dd.addin.stop()993 raise test_exception994 return dd.addin995def test_dropdown_dotted():996 try:997 ctrl = faf.Workspace().tab().panel().dropdown().control()998 except Exception as test_exception:999 ctrl.addin.stop()1000 raise test_exception1001 return ctrl.addin1002def test_dropdown_nested():1003 try:1004 ctrl = (1005 faf.Workspace()1006 .tab()1007 .panel()1008 .dropdown()1009 .dropdown()1010 .dropdown()1011 .dropdown()1012 .control()1013 )1014 except Exception as test_exception:1015 ctrl.addin.stop()1016 raise test_exception1017 return ctrl.addin1018def test_dropdown_properties():1019 try:1020 dd = faf.Dropdown(1021 id="test_dropdown_properties_id",1022 text="dd_name",1023 resourceFolder=r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one",1024 isVisible=True,1025 )1026 ctrl = faf.Control(dd)1027 assert dd.uiLevel == 41028 print(dd.controls)1029 assert dd.id == "test_dropdown_properties_id"1030 print(dd.index)1031 assert dd.isValid == True1032 print(dd.isVisible)1033 assert dd.name == "dd_name"1034 print(dd.objectType)1035 print(dd.parent)1036 assert (1037 dd.resourceFolder1038 == r"C:/Users/mohes/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/fusion_addin_framework/tests/test_images/one"1039 )1040 except Exception as test_exception:1041 dd.addin.stop()1042 raise test_exception...

Full Screen

Full Screen

test_exception_logging.py

Source:test_exception_logging.py Github

copy

Full Screen

1from collections import defaultdict2from six import text_type3from security_monkey.datastore import Account, Technology, Item4from security_monkey.datastore import store_exception, ExceptionLogs5from security_monkey.datastore import clear_old_exceptions, AccountType6from security_monkey import db, ARN_PREFIX7from security_monkey.tests import SecurityMonkeyTestCase8import traceback9import datetime10import random11import string12class ExceptionLoggingTestCase(SecurityMonkeyTestCase):13 def pre_test_setup(self):14 account_type_result = AccountType.query.filter(AccountType.name == 'AWS').first()15 if not account_type_result:16 account_type_result = AccountType(name='AWS')17 db.session.add(account_type_result)18 db.session.commit()19 self.account = Account(identifier="012345678910", name="testing",20 account_type_id=account_type_result.id)21 self.technology = Technology(name="iamrole")22 self.item = Item(region="us-west-2", name="testrole",23 arn=ARN_PREFIX + ":iam::012345678910:role/testrole", technology=self.technology,24 account=self.account)25 db.session.add(self.account)26 db.session.add(self.technology)27 db.session.add(self.item)28 db.session.commit()29 def tearDown(self):30 import security_monkey.auditor31 security_monkey.auditor.auditor_registry = defaultdict(list)32 super(ExceptionLoggingTestCase, self).tearDown()33 def test_doesnt_delete_parent_cascade(self):34 """35 If the exception is deleted, the parent (tech., item, account) should not be deleted.36 :return:37 """38 try:39 raise ValueError("This is a test")40 except ValueError as e:41 test_exception = e42 location = ("iamrole", "testing", "us-west-2", "testrole")43 store_exception("tests", location, test_exception)44 exc = ExceptionLogs.query.all()45 db.session.delete(exc[0])46 db.session.commit()47 assert len(Item.query.filter(Item.name == "testrole").all()) == 148 assert len(Technology.query.filter(Technology.name == "iamrole").all()) == 149 assert len(Account.query.filter(Account.name == "testing").all()) == 150 def test_child_deletion_cascade_check(self):51 """52 If the exception object is deleted, then the parent object (items, account, tech.) should NOT be deleted.53 :return:54 """55 try:56 raise ValueError("This is a test")57 except ValueError as e:58 test_exception = e59 location = ("iamrole", "testing", "us-west-2", "testrole")60 store_exception("tests", location, test_exception)61 assert len(self.item.exceptions) == 162 assert len(self.account.exceptions) == 163 assert len(self.technology.exceptions) == 164 db.session.delete(self.item.exceptions[0])65 db.session.commit()66 exc = ExceptionLogs.query.all()67 assert len(exc) == 068 assert len(Item.query.filter(Item.name == "testrole").all()) == 169 assert len(Technology.query.filter(Technology.name == "iamrole").all()) == 170 assert len(Account.query.filter(Account.name == "testing").all()) == 171 assert len(self.item.exceptions) == 072 assert len(self.account.exceptions) == 073 assert len(self.technology.exceptions) == 074 def test_safe_child_deletion_cascade(self):75 """76 If the parent is deleted (item, account, tech.), the exception should be deleted, BUT the other parents77 should remain.78 :return:79 """80 try:81 raise ValueError("This is a test")82 except ValueError as e:83 test_exception = e84 location = ("iamrole", "testing", "us-west-2", "testrole")85 store_exception("tests", location, test_exception)86 db.session.delete(self.item)87 db.session.commit()88 exc = ExceptionLogs.query.all()89 assert len(exc) == 090 assert len(Item.query.filter(Item.name == "testrole").all()) == 091 assert len(Technology.query.filter(Technology.name == "iamrole").all()) == 192 assert len(Account.query.filter(Account.name == "testing").all()) == 193 def test_store_exception(self):94 try:95 raise ValueError("This is a test")96 except ValueError as e:97 test_exception = e98 attrs = [99 ("technology", "iamrole"),100 ("account", "testing"),101 ("region", "us-west-2"),102 ("item", "testrole")103 ]104 location = ("iamrole", "testing", "us-west-2", "testrole")105 ttl_month = (datetime.datetime.utcnow() + datetime.timedelta(days=10)).month106 ttl_day = (datetime.datetime.utcnow() + datetime.timedelta(days=10)).day107 current_month = datetime.datetime.utcnow().month108 current_day = datetime.datetime.utcnow().day109 # Test all cases...110 for i in range(1, 5):111 store_exception("tests", tuple(location[:i]), test_exception)112 # Fetch the exception and validate it:113 exc_log = ExceptionLogs.query.order_by(ExceptionLogs.id.desc()).first()114 assert exc_log.type == type(test_exception).__name__115 assert exc_log.message == str(test_exception)116 assert exc_log.stacktrace == traceback.format_exc()117 assert exc_log.occurred.day == current_day118 assert exc_log.occurred.month == current_month119 assert exc_log.ttl.month == ttl_month120 assert exc_log.ttl.day == ttl_day121 for x in range(0, i):122 attr = getattr(exc_log, attrs[x][0])123 if isinstance(attr, text_type):124 assert attr == attrs[x][1]125 else:126 assert attr.name == attrs[x][1]127 assert len(self.account.exceptions) == 3128 assert len(self.technology.exceptions) == 4129 assert len(self.item.exceptions) == 1130 def test_exception_length(self):131 some_string = "".join(random.choice(string.ascii_uppercase) for _ in range(1024))132 try:133 raise ValueError(some_string)134 except ValueError as e:135 test_exception = e136 location = ("iamrole", "testing", "us-west-2", "testrole")137 store_exception("tests", location, test_exception)138 exc_log = ExceptionLogs.query.order_by(ExceptionLogs.id.desc()).first()139 assert len(exc_log.message) == 512140 assert exc_log.message[:512] == some_string[:512]141 def test_exception_clearing(self):142 location = ("iamrole", "testing", "us-west-2", "testrole")143 for i in range(0, 5):144 try:145 raise ValueError("This is test: {}".format(i))146 except ValueError as e:147 test_exception = e148 store_exception("tests", location, test_exception,149 ttl=(datetime.datetime.now() - datetime.timedelta(days=1)))150 store_exception("tests", location, test_exception)151 clear_old_exceptions()152 # Get all the exceptions:153 exc_list = ExceptionLogs.query.all()154 assert len(exc_list) == 1155 def test_store_exception_with_new_techid(self):156 try:157 raise ValueError("This is a test")158 except ValueError as e:159 test_exception = e160 location = ['newtech']161 ttl_month = (datetime.datetime.utcnow() + datetime.timedelta(days=10)).month162 ttl_day = (datetime.datetime.utcnow() + datetime.timedelta(days=10)).day163 current_month = datetime.datetime.utcnow().month164 current_day = datetime.datetime.utcnow().day165 store_exception("tests", location, test_exception)166 # Fetch the exception and validate it:167 exc_logs = ExceptionLogs.query.all()168 assert len(exc_logs) == 1169 exc_log = exc_logs[0]170 assert exc_log.type == type(test_exception).__name__171 assert exc_log.message == str(test_exception)172 assert exc_log.stacktrace == traceback.format_exc()173 assert exc_log.occurred.day == current_day174 assert exc_log.occurred.month == current_month175 assert exc_log.ttl.month == ttl_month176 assert exc_log.ttl.day == ttl_day177 tech = Technology.query.filter(Technology.name == "newtech").first()178 assert tech...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

1'use strict';2// Flags: --expose-gc3const common = require('../../common');4const assert = require('assert');5const theError = new Error('Some error');6// The test module throws an error during Init, but in order for its exports to7// not be lost, it attaches them to the error's "bindings" property. This way,8// we can make sure that exceptions thrown during the module initialization9// phase are propagated through require() into JavaScript.10// https://github.com/nodejs/node/issues/1943711const test_exception = (function() {12 let resultingException;13 try {14 require(`./build/${common.buildType}/test_exception`);15 } catch (anException) {16 resultingException = anException;17 }18 assert.strictEqual(resultingException.message, 'Error during Init');19 return resultingException.binding;20})();21{22 const throwTheError = () => { throw theError; };23 // Test that the native side successfully captures the exception24 let returnedError = test_exception.returnException(throwTheError);25 assert.strictEqual(returnedError, theError);26 // Test that the native side passes the exception through27 assert.throws(28 () => { test_exception.allowException(throwTheError); },29 (err) => err === theError30 );31 // Test that the exception thrown above was marked as pending32 // before it was handled on the JS side33 const exception_pending = test_exception.wasPending();34 assert.strictEqual(exception_pending, true,35 'Exception not pending as expected,' +36 ` .wasPending() returned ${exception_pending}`);37 // Test that the native side does not capture a non-existing exception38 returnedError = test_exception.returnException(common.mustCall());39 assert.strictEqual(returnedError, undefined,40 'Returned error should be undefined when no exception is' +41 ` thrown, but ${returnedError} was passed`);42}43{44 const throwTheError = class { constructor() { throw theError; } };45 // Test that the native side successfully captures the exception46 let returnedError = test_exception.constructReturnException(throwTheError);47 assert.strictEqual(returnedError, theError);48 // Test that the native side passes the exception through49 assert.throws(50 () => { test_exception.constructAllowException(throwTheError); },51 (err) => err === theError52 );53 // Test that the exception thrown above was marked as pending54 // before it was handled on the JS side55 const exception_pending = test_exception.wasPending();56 assert.strictEqual(exception_pending, true,57 'Exception not pending as expected,' +58 ` .wasPending() returned ${exception_pending}`);59 // Test that the native side does not capture a non-existing exception60 returnedError = test_exception.constructReturnException(common.mustCall());61 assert.strictEqual(returnedError, undefined,62 'Returned error should be undefined when no exception is' +63 ` thrown, but ${returnedError} was passed`);64}65{66 // Test that no exception appears that was not thrown by us67 let caughtError;68 try {69 test_exception.allowException(common.mustCall());70 } catch (anError) {71 caughtError = anError;72 }73 assert.strictEqual(caughtError, undefined,74 'No exception originated on the native side, but' +75 ` ${caughtError} was passed`);76 // Test that the exception state remains clear when no exception is thrown77 const exception_pending = test_exception.wasPending();78 assert.strictEqual(exception_pending, false,79 'Exception state did not remain clear as expected,' +80 ` .wasPending() returned ${exception_pending}`);81}82{83 // Test that no exception appears that was not thrown by us84 let caughtError;85 try {86 test_exception.constructAllowException(common.mustCall());87 } catch (anError) {88 caughtError = anError;89 }90 assert.strictEqual(caughtError, undefined,91 'No exception originated on the native side, but' +92 ` ${caughtError} was passed`);93 // Test that the exception state remains clear when no exception is thrown94 const exception_pending = test_exception.wasPending();95 assert.strictEqual(exception_pending, false,96 'Exception state did not remain clear as expected,' +97 ` .wasPending() returned ${exception_pending}`);...

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 green 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