How to use sortItems method in fMBT

Best Python code snippet using fMBT_python

bases.py

Source:bases.py Github

copy

Full Screen

1"""Provides the Module and Type base classes that user code inherits from."""2__all__ = ["Module", "Type", "member"]3from framer import struct, template4from framer.function import Function, Method5from framer.member import member6from framer.slots import *7from framer.util import cstring, unindent8from types import FunctionType9def sortitems(dict):10 L = dict.items()11 L.sort()12 return L13# The Module and Type classes are implemented using metaclasses,14# because most of the methods are class methods. It is easier to use15# metaclasses than the cumbersome classmethod() builtin. They have16# class methods because they are exposed to user code as base classes.17class BaseMetaclass(type):18 """Shared infrastructure for generating modules and types."""19 # just methoddef so far20 def dump_methoddef(self, f, functions, vars):21 def p(templ, vars=vars): # helper function to generate output22 print >> f, templ % vars23 if not functions:24 return25 p(template.methoddef_start)26 for name, func in sortitems(functions):27 if func.__doc__:28 p(template.methoddef_def_doc, func.vars)29 else:30 p(template.methoddef_def, func.vars)31 p(template.methoddef_end)32class ModuleMetaclass(BaseMetaclass):33 """Provides methods for Module class."""34 def gen(self):35 self.analyze()36 self.initvars()37 f = open(self.__filename, "w")38 self.dump(f)39 f.close()40 def analyze(self):41 self.name = getattr(self, "abbrev", self.__name__)42 self.__functions = {}43 self.__types = {}44 self.__members = False45 for name, obj in self.__dict__.iteritems():46 if isinstance(obj, FunctionType):47 self.__functions[name] = Function(obj, self)48 elif isinstance(obj, TypeMetaclass):49 obj._TypeMetaclass__module = self.name50 obj.analyze()51 self.__types[name] = obj52 if obj.has_members():53 self.__members = True54 def initvars(self):55 v = self.__vars = {}56 filename = getattr(self, "__file__", None)57 if filename is None:58 filename = self.__name__ + "module.c"59 self.__filename = v["FileName"] = filename60 name = v["ModuleName"] = self.__name__61 v["MethodDefName"] = "%s_methods" % name62 v["ModuleDocstring"] = cstring(unindent(self.__doc__))63 def dump(self, f):64 def p(templ, vars=self.__vars): # helper function to generate output65 print >> f, templ % vars66 p(template.module_start)67 if self.__members:68 p(template.member_include)69 print >> f70 if self.__doc__:71 p(template.module_doc)72 for name, type in sortitems(self.__types):73 type.dump(f)74 for name, func in sortitems(self.__functions):75 func.dump(f)76 self.dump_methoddef(f, self.__functions, self.__vars)77 p(template.module_init_start)78 for name, type in sortitems(self.__types):79 type.dump_init(f)80 p("}")81class Module:82 __metaclass__ = ModuleMetaclass83class TypeMetaclass(BaseMetaclass):84 def dump(self, f):85 self.initvars()86 # defined after initvars() so that __vars is defined87 def p(templ, vars=self.__vars):88 print >> f, templ % vars89 if self.struct is not None:90 print >> f, unindent(self.struct, False)91 if self.__doc__:92 p(template.docstring)93 for name, func in sortitems(self.__methods):94 func.dump(f)95 self.dump_methoddef(f, self.__methods, self.__vars)96 self.dump_memberdef(f)97 self.dump_slots(f)98 def has_members(self):99 if self.__members:100 return True101 else:102 return False103 def analyze(self):104 # called by ModuleMetaclass analyze()105 self.name = getattr(self, "abbrev", self.__name__)106 src = getattr(self, "struct", None)107 if src is not None:108 self.__struct = struct.parse(src)109 else:110 self.__struct = None111 self.__methods = {}112 self.__members = {}113 for cls in self.__mro__:114 for k, v in cls.__dict__.iteritems():115 if isinstance(v, FunctionType):116 self.__methods[k] = Method(v, self)117 if isinstance(v, member):118 self.__members[k] = v119 assert self.__struct is not None120 v.register(k, self.__struct)121 self.analyze_slots()122 def analyze_slots(self):123 self.__slots = {}124 for s in Slots:125 if s.special is not None:126 meth = self.__methods.get(s.special)127 if meth is not None:128 self.__slots[s] = meth129 self.__slots[TP_NAME] = '"%s.%s"' % (self.__module, self.__name__)130 if self.__doc__:131 self.__slots[TP_DOC] = "%s_doc" % self.name132 if self.__struct is not None:133 self.__slots[TP_BASICSIZE] = "sizeof(%s)" % self.__struct.name134 self.__slots[TP_DEALLOC] = "%s_dealloc" % self.name135 if self.__methods:136 self.__slots[TP_METHODS] = "%s_methods" % self.name137 if self.__members:138 self.__slots[TP_MEMBERS] = "%s_members" % self.name139 def initvars(self):140 v = self.__vars = {}141 v["TypeName"] = self.__name__142 v["CTypeName"] = "Py%s_Type" % self.__name__143 v["MethodDefName"] = self.__slots[TP_METHODS]144 if self.__doc__:145 v["DocstringVar"] = self.__slots[TP_DOC]146 v["Docstring"] = cstring(unindent(self.__doc__))147 if self.__struct is not None:148 v["StructName"] = self.__struct.name149 if self.__members:150 v["MemberDefName"] = self.__slots[TP_MEMBERS]151 def dump_memberdef(self, f):152 def p(templ, vars=self.__vars):153 print >> f, templ % vars154 if not self.__members:155 return156 p(template.memberdef_start)157 for name, slot in sortitems(self.__members):158 slot.dump(f)159 p(template.memberdef_end)160 def dump_slots(self, f):161 def p(templ, vars=self.__vars):162 print >> f, templ % vars163 if self.struct:164 p(template.dealloc_func, {"name" : self.__slots[TP_DEALLOC]})165 p(template.type_struct_start)166 for s in Slots[:-5]: # XXX167 val = self.__slots.get(s, s.default)168 ntabs = 4 - (4 + len(val)) / 8169 line = " %s,%s/* %s */" % (val, "\t" * ntabs, s.name)170 print >> f, line171 p(template.type_struct_end)172 def dump_init(self, f):173 def p(templ):174 print >> f, templ % self.__vars175 p(template.type_init_type)176 p(template.module_add_type)177class Type:...

Full Screen

Full Screen

compartments_list_widget.py

Source:compartments_list_widget.py Github

copy

Full Screen

...25 return (float(y), float(x))26 add_actions(self,27 [28 None,29 create_action(self, 'Sort by name then x then y ascending', lambda: self.sortItems(regex_functions=[(pattern, name_then_x_then_y)])),30 create_action(self, 'Sort by name then x then y descending', lambda: self.sortItems(order=Qt.DescendingOrder, regex_functions=[(pattern, name_then_x_then_y)])),31 None,32 create_action(self, 'Sort by name then y then x ascending', lambda: self.sortItems(regex_functions=[(pattern, name_then_y_then_x)])),33 create_action(self, 'Sort by name then y then x descending', lambda: self.sortItems(order=Qt.DescendingOrder, regex_functions=[(pattern, name_then_y_then_x)])),34 None,35 create_action(self, 'Sort by x then y ascending', lambda: self.sortItems(regex_functions=[(pattern, x_then_y)])),36 create_action(self, 'Sort by x then y descending', lambda: self.sortItems(order=Qt.DescendingOrder, regex_functions=[(pattern, x_then_y)])),37 None,38 create_action(self, 'Sort by y then x ascending', lambda: self.sortItems(regex_functions=[(pattern, y_then_x)])),39 create_action(self, 'Sort by y then x descending', lambda: self.sortItems(order=Qt.DescendingOrder, regex_functions=[(pattern, y_then_x)])),40 ]...

Full Screen

Full Screen

test_1203_sort_items_by_groups_respecting_dependencies.py

Source:test_1203_sort_items_by_groups_respecting_dependencies.py Github

copy

Full Screen

1from unittest import TestCase2from problems.N1203_Sort_Items_By_Groups_Respecting_Dependencies import Solution3class TestSolution(TestCase):4 def test_sortItems(self):5 self.assertListEqual([0, 5, 2, 6, 3, 4, 7, 1], Solution().sortItems(n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]]))6 def test_sortItems_1(self):7 self.assertListEqual([], Solution().sortItems(n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]]))8 def test_sortItems_2(self):9 self.assertListEqual([2, 3, 4, 1, 0], Solution().sortItems(n = 5, m = 5, group = [2,0,-1,3,0], beforeItems = [[2,1,3],[2,4],[],[],[]]))10 def test_sortItems_3(self):...

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