def main(): base_imports = get_base_import_names() #rmtree(pkg_name, 'nastranwrapper-using_pynastran') #cleanup() folders, fnames = get_folders_files(pkg_name) n = len(sys.path) for fname in fnames: class_names, function_names = get_class_function_list(fname) if len(class_names + function_names): dirname = os.path.dirname(fname) basename = os.path.basename(fname).split('.')[0] basename2 = fname.split('.')[0] #print('basename =', basename) if 'gui' in fname or 'test' in fname: continue sys.path.insert(n, dirname) module = importlib.import_module(basename) # remove __methods__ public = [ key for key in sorted(module.__dict__) if not key.startswith('__') and not key.endswith('__') and key not in base_imports and 'test' not in key.lower() ] if public: print(fname) print(public) for class_name in class_names: if class_name not in public: continue try: class_obj = getattr(module, class_name) except AttributeError: print('bad_module=%s' % fname) raise object_methods(class_obj) if function_names: for function_name in function_names: func = getattr(module, function_name) fargs = get_function_args(func, function_name) #print(function_names) print('') #for function_name in function_names: #print(object_methods(class_obj)) #sys.path.pop() #del module del sys.modules[basename]
def test_object_methods_introspection(self): methods = object_methods(self.b) self.assertEqual(methods, ['getA', 'getB']) methods = object_methods(self.b, "private") self.assertEqual(methods, ['_getA', '_getB']) methods = object_methods(self.b, "both") self.assertEqual(methods, ['_getA', '_getB', 'getA', 'getB']) methods = object_methods(self.b, "all") self.assertEqual(methods, ['__init__', '_getA', '_getB', 'getA', 'getB'])
def test_object_methods_introspection(self): methods = object_methods(self.b) self.assertEqual(methods, ['getA', 'getB']) methods = object_methods(self.b, "private") self.assertEqual(methods, ['_getA', '_getB']) methods = object_methods(self.b, "both") self.assertEqual(methods, ['_getA', '_getB', 'getA', 'getB']) methods = object_methods(self.b, "all") self.assertEqual(methods, ['__init__', '_getA', '_getB', 'getA', 'getB'])
def main(): base_imports = get_base_import_names() #rmtree(pkg_name, 'nastranwrapper-using_pynastran') #cleanup() folders, fnames = get_folders_files(pkg_name) n = len(sys.path) for fname in fnames: class_names, function_names = get_class_function_list(fname) if len(class_names + function_names): dirname = os.path.dirname(fname) basename = os.path.basename(fname).split('.')[0] basename2 = fname.split('.')[0] #print('basename =', basename) if 'gui' in fname or 'test' in fname: continue sys.path.insert(n, dirname) module = importlib.import_module(basename) # remove __methods__ public = [key for key in sorted(module.__dict__) if not key.startswith('__') and not key.endswith('__') and key not in base_imports and 'test' not in key.lower()] if public: print(fname) print(public) for class_name in class_names: if class_name not in public: continue try: class_obj = getattr(module, class_name) except AttributeError: print('bad_module=%s' % fname) raise object_methods(class_obj) if function_names: for function_name in function_names: func = getattr(module, function_name) fargs = get_function_args(func, function_name) #print(function_names) print('') #for function_name in function_names: #print(object_methods(class_obj)) #sys.path.pop() #del module del sys.modules[basename]
def test_object_methods_introspection(self): """object methods determines the public/private methods of a class""" b = B1(7) methods = object_methods(b) self.assertEqual(methods, ["getA", "getB"]) methods = object_methods(b, "private") self.assertEqual(methods, ["_getA", "_getB"]) methods = object_methods(b, "both") self.assertEqual(methods, ["_getA", "_getB", "getA", "getB"]) methods = object_methods(b, "all") self.assertEqual(methods, ["__init__", "_getA", "_getB", "getA", "getB"])
def test_object_methods_introspection(self): """object methods determines the public/private methods of a class""" b = B1(7) methods = object_methods(b) self.assertEqual(methods, ['getA', 'getB']) methods = object_methods(b, "private") self.assertEqual(methods, ['_getA', '_getB']) methods = object_methods(b, "both") self.assertEqual(methods, ['_getA', '_getB', 'getA', 'getB']) methods = object_methods(b, "all") self.assertEqual(methods, ['__init__', '_getA', '_getB', 'getA', 'getB'])
def object_methods(self, mode='public', keys_to_skip=None): """ List the names of methods of a class as strings. Returns public methods as default. Parameters ---------- obj : instance the object for checking mode : str defines what kind of methods will be listed * "public" - names that do not begin with underscore * "private" - names that begin with single underscore * "both" - private and public * "all" - all methods that are defined for the object keys_to_skip : List[str]; default=None -> [] names to not consider to avoid deprecation warnings Returns ------- method : List[str] sorted list of the names of methods of a given type or None if the mode is wrong """ return object_methods(self, mode=mode, keys_to_skip=keys_to_skip)
def object_methods(self, mode="public", keys_to_skip=None): if keys_to_skip is None: keys_to_skip = [] my_keys_to_skip = [] my_keys_to_skip = ["object_methods", "object_attributes"] return object_methods(self, mode=mode, keys_to_skip=keys_to_skip + my_keys_to_skip)
def object_methods(self, mode: str='public', keys_to_skip: Optional[List[str]]=None) -> List[str]: """.. seealso:: `pyNastran.utils.object_methods(...)`""" if keys_to_skip is None: keys_to_skip = [] my_keys_to_skip = [] # type: List[str] return object_methods(self, mode=mode, keys_to_skip=keys_to_skip+my_keys_to_skip)
def object_methods(self, mode='public', keys_to_skip=None): """ List the names of methods of a class as strings. Returns public methods as default. Parameters ---------- obj : instance the object for checking mode : str defines what kind of methods will be listed * "public" - names that do not begin with underscore * "private" - names that begin with single underscore * "both" - private and public * "all" - all methods that are defined for the object keys_to_skip : List[str]; default=None -> [] names to not consider to avoid deprecation warnings Returns ------- method : List[str] sorted list of the names of methods of a given type or None if the mode is wrong """ return object_methods(obj, mode=mode, keys_to_skip=keys_to_skip)
def object_methods(self, mode="public", keys_to_skip=None): """..see:: `pyNastran.utils.object_methods(...)`""" if keys_to_skip is None: keys_to_skip = [] my_keys_to_skip = [] my_keys_to_skip = [] return object_methods(self, mode=mode, keys_to_skip=keys_to_skip + my_keys_to_skip)
def object_methods(self, mode='public', keys_to_skip=None): """.. seealso:: `pyNastran.utils.object_methods(...)`""" if keys_to_skip is None: keys_to_skip = [] my_keys_to_skip = [] return object_methods(self, mode=mode, keys_to_skip=keys_to_skip + my_keys_to_skip)
def object_methods(self, mode='public', keys_to_skip=None): if keys_to_skip is None: keys_to_skip = [] my_keys_to_skip = [] my_keys_to_skip = [ ] return object_methods(self, mode=mode, keys_to_skip=keys_to_skip+my_keys_to_skip)
def object_methods(self, mode='public', keys_to_skip=None): if keys_to_skip is None: keys_to_skip = [] my_keys_to_skip = [] my_keys_to_skip = [ 'object_methods', 'object_attributes', ] return object_methods(self, mode=mode, keys_to_skip=keys_to_skip+my_keys_to_skip)
def object_methods(self, mode: str = 'public', keys_to_skip: Optional[List[str]] = None) -> List[str]: """ List the names of methods of a class as strings. Returns public methods as default. Parameters ---------- obj : instance the object for checking mode : str defines what kind of methods will be listed * "public" - names that do not begin with underscore * "private" - names that begin with single underscore * "both" - private and public * "all" - all methods that are defined for the object keys_to_skip : List[str]; default=None -> [] names to not consider to avoid deprecation warnings Returns ------- method : List[str] sorted list of the names of methods of a given type or None if the mode is wrong """ if keys_to_skip is None: keys_to_skip = [] my_keys_to_skip = [] # type: List[str] my_keys_to_skip = [ #'case_control_deck', 'log', #'mpcObject', 'spcObject', 'node_ids', 'coord_ids', 'element_ids', 'property_ids', 'material_ids', 'caero_ids', 'is_long_ids', 'nnodes', 'ncoords', 'nelements', 'nproperties', 'nmaterials', 'ncaeros', 'point_ids', 'subcases', '_card_parser', '_card_parser_b', 'object_methods', 'object_attributes', ] return object_methods(self, mode=mode, keys_to_skip=keys_to_skip + my_keys_to_skip)
def object_methods(self, mode='public', keys_to_skip=None): if keys_to_skip is None: keys_to_skip = [] my_keys_to_skip = [] my_keys_to_skip = [ #'case_control_deck', 'log', 'mpcObject', 'spcObject', 'node_ids', 'coord_ids', 'element_ids', 'property_ids', 'material_ids', 'caero_ids', 'is_long_ids', 'nnodes', 'ncoords', 'nelements', 'nproperties', 'nmaterials', 'ncaeros', 'point_ids', 'subcases', '_card_parser', '_card_parser_b', 'object_methods', 'object_attributes', ] return object_methods(self, mode=mode, keys_to_skip=keys_to_skip+my_keys_to_skip)
def object_methods(self, mode='public', keys_to_skip=None): """ List the names of methods of a class as strings. Returns public methods as default. Parameters ---------- obj : instance the object for checking mode : str defines what kind of methods will be listed * "public" - names that do not begin with underscore * "private" - names that begin with single underscore * "both" - private and public * "all" - all methods that are defined for the object keys_to_skip : List[str]; default=None -> [] names to not consider to avoid deprecation warnings Returns ------- method : List[str] sorted list of the names of methods of a given type or None if the mode is wrong """ if keys_to_skip is None: keys_to_skip = [] my_keys_to_skip = [] my_keys_to_skip = [ #'case_control_deck', 'log', #'mpcObject', 'spcObject', 'node_ids', 'coord_ids', 'element_ids', 'property_ids', 'material_ids', 'caero_ids', 'is_long_ids', 'nnodes', 'ncoords', 'nelements', 'nproperties', 'nmaterials', 'ncaeros', 'point_ids', 'subcases', '_card_parser', '_card_parser_b', 'object_methods', 'object_attributes', ] return object_methods(self, mode=mode, keys_to_skip=keys_to_skip+my_keys_to_skip)
* "all" - all methods that are defined for the object keys_to_skip : List[str]; default=None -> [] names to not consider to avoid deprecation warnings Returns ------- method : List[str] sorted list of the names of methods of a given type or None if the mode is wrong """ if keys_to_skip is None: keys_to_skip = [] my_keys_to_skip = ['object_methods', 'object_attributes'] keys_to_skip += my_keys_to_skip return object_methods(self, mode=mode, keys_to_skip=keys_to_skip) def __eq__(self, op2_model) -> bool: """Diffs the current op2 model vs. another op2 model. Crashes if they're not equal. """ try: is_equal = self.assert_op2_equal( op2_model, stop_on_failure=True, debug=False) except (AssertionError, ValueError): is_equal = False raise return is_equal def assert_op2_equal(
bdf.read_bdf(bdf_filename, xref=False) # <codecell> #bdf_filename = r'D:\work\pynastran_0.7.0_py27\models\iSat\ISat_Launch_Sm_Rgd.dat' bdf_filename = r'C:\Users\Steve\Dropbox\pyNastran_examples\iSat\ISat_Launch_Sm_Rgd.dat' # read the file as a path bdf2 = BDF() bdf2.read_bdf(bdf_filename, xref=True) # <codecell> print "attributes =", object_attributes(bdf) print "" print "methods =",object_methods(bdf) print bdf.card_stats() print bdf.card_count # <codecell> # explanation of cross-referencing # no cross referencing (xref=False) cquad = bdf.elements[1] nid1 = cquad.nodes[0] n1 = bdf.nodes[nid1] cd4 = n1.cd c4 = bdf.coords[cd4] print "i xref=False", c4.i #print object_attributes(c4)
def test_object_methods_02(self): """tests getting object methods from the method""" model = BDF(debug=False) keys = [] object_methods(model, mode="public", keys_to_skip=keys)
#print "n1 = ", case3[m0] plate_stress = op2.plateStress[1] print "plate_stress_obj =", type(plate_stress) print "plate_stress = ", plate_stress.__dict__.keys() plate_stress.ovmShear.keys() # 1-6 plate_stress.data_code #type(plate_stress) def abs_max_min(vals): maxval = max(abs(vals)) i = vals.index(maxval) return vals[i] object_methods(plate_stress) plate_stress.isVonMises() # True ovm = plate_stress.ovmShear #ovm.keys() # modes 1-6 #ovm[6].keys() # elements 1-3277 print "vals =", ovm[6][1000]['C'] ovm_mode6_eid1000 = abs_max_min(ovm[6][1000]['C']) print "ovm_mode6_eid1000 =", ovm_mode6_eid1000 ps = copy.deepcopy(plate_stress) # <codecell> ps = copy.deepcopy(plate_stress) print "ps.mode_cycles", ps.mode_cycles
# 1 or more matrices matrices = op4.read_op4(op4_filename, matrix_names=['FLAMA','UGEXT']) # <codecell> # extract a matrix form, flama = matrices['FLAMA'] print "form =", form print "type =", type(flama) # <codecell> from pyNastran.utils import object_methods print "keys =", matrices.keys() print "object_methods", object_methods(op4) #op4.getTypeNWV? # <codecell> print matrices.keys() form_flama, flama = matrices['FLAMA'] print "shape = ", flama.shape print "flamat nvals =", product(flama.shape) form_ugext, ugext = matrices['UGEXT'] print "form_ugext=%s type=%s" % (form_ugext, type(ugext[0,0])) #print "ugext", ugext print "ugext.shape =", ugext.shape print "ugext nvals =", product(ugext.shape)
# for transient, it's "dts" print "modes = ", plate_stress.modes # name + 's' # extra list-type parameter for modal analysis; see dataNames #print "mode_cycles =", plate_stress.mode_cycles # <codecell> def abs_max_min(vals): absvals = list(abs(vals)) maxval = max(absvals) i = absvals.index(maxval) return vals[i] print "methods =", object_methods(plate_stress) if plate_stress.isVonMises(): # True ovm = plate_stress.ovmShear else: oMaxShear = plate_stress.ovmShear #ovm.keys() # modes 1-6 #ovm[6].keys() # elements 1-3277 print "" print "[layer1, layer2, ...] =", ovm[6][1000]['C'] ovm_mode6_eid1000 = abs_max_min(ovm[6][1000]['C']) print "ovm_mode6_eid1000 =", ovm_mode6_eid1000 # <codecell> # see the difference between "transient"/"modal"/"frequency"-style results
# for transient, it's "dts" print ("modes = ", plate_stress.modes) # name + 's' # extra list-type parameter for modal analysis; see dataNames #print "mode_cycles =", plate_stress.mode_cycles # <codecell> def abs_max_min(vals): absvals = list(abs(vals)) maxval = max(absvals) i = absvals.index(maxval) return vals[i] print ("methods =", object_methods(plate_stress)) if plate_stress.isVonMises(): # True ovm = plate_stress.ovmShear else: oMaxShear = plate_stress.ovmShear #ovm.keys() # modes 1-6 #ovm[6].keys() # elements 1-3277 print ("") print ("[layer1, layer2, ...] =", ovm[6][1000]['C']) ovm_mode6_eid1000 = abs_max_min(ovm[6][1000]['C']) print ("ovm_mode6_eid1000 =", ovm_mode6_eid1000) # <codecell> # see the difference between "transient"/"modal"/"frequency"-style results
def test_object_methods_02(self): model = BDF(debug=False) keys = [] object_methods(model, mode="public", keys_to_skip=keys)
def test_object_methods_02(self): """tests getting object methods from the method""" model = BDF(debug=False) keys = [] object_methods(model, mode="public", keys_to_skip=keys)
def object_methods(self): return object_methods(self, keys_to_skip=['object_attributes', 'object_methods'])