def test_create_project(self): creation_path = ProjectTests.get_temp_dirname("testProject") test_project = Project.create(creation_path) # Assertions self.assertTrue(os.path.exists(test_project.path)) self.assertEqual(environFn.get_project_var(), test_project) self.assertTrue(os.path.exists(test_project.tag_path)) self.assertTrue(os.path.exists(test_project.meta_path)) self.assertEqual(Config.get(ProjectVars.previous_project), test_project.path) self.assertIn([test_project.name, test_project.path], Config.get(ProjectVars.recent_projects))
def add_to_recent(self): max_recent = Config.get(ProjectVars.recent_max, default=3) project_queue = Config.get(ProjectVars.recent_projects, default=deque(maxlen=max_recent)) if not isinstance(project_queue, deque): project_queue = deque(project_queue, maxlen=max_recent) entry = [self.name, self.path] if entry in project_queue: return project_queue.appendleft(entry) Config.set(ProjectVars.recent_projects, list(project_queue))
class LunaHud: HUD_NAME = "LunaHud" UPDATE_EVENT = "SceneOpened" SECTION = Config.get(HudVars.section, default=7) BLOCK = Config.get(HudVars.block, default=5) BLOCK_SIZE = "medium" FONT_SIZE = "large" @classmethod def create(cls): hud_instance = None Logger.info("Building {0}...".format(cls.HUD_NAME)) # Delete old cls.remove() hud_instance = pm.headsUpDisplay(cls.HUD_NAME, section=cls.SECTION, block=cls.BLOCK, blockSize=cls.BLOCK_SIZE, labelFontSize=cls.FONT_SIZE, command=cls.getHudText, event=cls.UPDATE_EVENT) Logger.info("Successfully created HUD: {0}".format(cls.HUD_NAME)) return hud_instance @classmethod def refresh(cls): try: pm.headsUpDisplay(cls.HUD_NAME, r=1) except BaseException: Logger.exception("Failed to refresh {0}".format(cls.HUD_NAME)) @classmethod def remove(cls): if pm.headsUpDisplay(cls.HUD_NAME, ex=1): pm.headsUpDisplay(cls.HUD_NAME, rem=1) @staticmethod def getHudText(): stringToDraw = "" current_project = environFn.get_project_var() current_asset = environFn.get_asset_var() if current_project: stringToDraw += current_project.name if current_asset: stringToDraw += " :: {0}".format(current_asset.name) else: stringToDraw = " " return stringToDraw
def run_all_tests(): test_suite = unittest.TestLoader().discover(start_dir=directories.TEST_DIR_PATH, pattern="*_test.py") Logger.info("Running {0} tests...".format(test_suite.countTestCases())) test_runner = unittest.TextTestRunner(verbosity=2, resultclass=TestResult) test_runner.failfast = False test_runner.buffer = Config.get(TestVars.buffer_output, default=True) test_runner.run(test_suite)
def stopTestRun(self): """Called after all tests are run.""" if Config.get(TestVars.buffer_output, default=True): # Restore logging state logging.disable(logging.NOTSET) ScriptEditorState.restore_output() super(TestResult, self).stopTestRun()
def refresh_recent(): recent_projects = Config.get(ProjectVars.recent_projects) existing_projects = [] for prj in recent_projects: if os.path.isdir(prj[1]): existing_projects.append(prj) Config.set(ProjectVars.recent_projects, existing_projects)
def startTestRun(self): """Called before any tests are run.""" super(TestResult, self).startTestRun() ScriptEditorState.suppress_output() if Config.get(TestVars.buffer_output, default=True): # Disable any logging while running tests. By disabling critical, we are disabling logging # at all levels below critical as well logging.disable(logging.CRITICAL)
def delete_temp_files(cls): """Delete the temp files in the cache and clear the cache.""" # If we don't want to keep temp files around for debugging purposes, delete them when # all tests in this TestCase have been run if Config.get(TestVars.delete_dirs, True): for d in cls.dirs_created: if os.path.isdir(d): shutil.rmtree(d) Logger.info("Deleted dir: {0}".format(d)) cls.dirs_created = [] if Config.get(TestVars.delete_files, default=True): for f in cls.files_created: if os.path.exists(f): os.remove(f) Logger.info("Deleted temp file: {0}".format(f)) cls.files_created = []
def stopTest(self, test): """Called after an individual test is run. Args: test ([type]): [description] """ super(TestResult, self).stopTest(test) if Config.get(TestVars.new_file, default=True): pm.newFile(f=1)
def get_temp_dirname(cls, dir_name): temp_dir = Config.get(TestVars.temp_dir) if not temp_dir: temp_dir = pm.internalVar(utd=1) path = os.path.join(temp_dir, dir_name) count = 0 while os.path.exists(path): count += 1 path = os.path.join(temp_dir, "{0}{1}".format(dir_name, count)) cls.dirs_created.append(path) return path
def suppress_output(cls): """Hides all script editor output.""" if Config.get(TestVars.buffer_output, default=True): cls.suppress_results = pm.scriptEditorInfo(q=True, suppressResults=True) cls.suppress_errors = pm.scriptEditorInfo(q=True, suppressErrors=True) cls.suppress_warnings = pm.scriptEditorInfo(q=True, suppressWarnings=True) cls.suppress_info = pm.scriptEditorInfo(q=True, suppressInfo=True) pm.scriptEditorInfo( e=True, suppressResults=True, suppressInfo=True, suppressWarnings=True, suppressErrors=True, )
def get_temp_filename(cls, file_name): temp_dir = Config.get(TestVars.temp_dir) if not temp_dir: temp_dir = pm.internalVar(utd=1) if not os.path.exists(temp_dir): os.makedirs(temp_dir) base_name, ext = os.path.splitext(file_name) path = os.path.join(temp_dir, base_name + ext) count = 0 while os.path.exists(path): count += 1 path = os.path.join(temp_dir, "{0}{1}{2}".format(base_name, count, ext)) cls.files_created.append(path) return path
def addMenuItem(parent=None, label="", command=_null_command, icon="", divider=False, option_box=False, check_box=False, use_maya_icons=False, var_name=None, default_value=False): if icon and not use_maya_icons: icon = fileFn.get_icon_path(icon) if divider: return pm.menuItem(p=parent, dl=label, i=icon, d=divider) elif option_box: return pm.menuItem(p=parent, l=label, i=icon, ob=option_box, c=command) elif check_box: if not var_name: Logger.error( "Menuitem: {0}::{1} is not connected to config!".format( parent, label)) return checkBox_value = Config.get(var_name, default_value) checkBox = pm.menuItem(p=parent, l=label, i=icon, cb=checkBox_value, c=partial(Config.set, var_name)) return checkBox else: return pm.menuItem(p=parent, l=label, i=icon, c=command)