How to use strip_py_ext method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

find.py

Source:find.py Github

copy

Full Screen

...106 for (prefix, prefix_package) in options.prefix:107 if fpath.startswith(prefix) and package == prefix_package:108 # strip prefix, strip .py suffix and convert separator to dots109 noprefix = fpath[len(prefix):]110 noext = strip_py_ext(options, noprefix)111 assert noext is not None112 module_name = noext.replace(os.path.sep, '.')113 if package:114 module_name = package + '.' + module_name115 for filter in options.module:116 if filter(module_name):117 break118 else:119 continue120 try:121 module = import_name(module_name)122 except KeyboardInterrupt:123 raise124 except:125 suite = StartUpFailure(126 options, module_name,127 sys.exc_info()[:2]128 + (sys.exc_info()[2].tb_next.tb_next,),129 )130 else:131 try:132 if hasattr(module, options.suite_name):133 suite = getattr(module, options.suite_name)()134 else:135 suite = unittest.defaultTestLoader.loadTestsFromModule(module)136 if suite.countTestCases() == 0:137 raise TypeError(138 "Module %s does not define any tests"139 % module_name)140 if isinstance(suite, unittest.TestSuite):141 check_suite(suite, module_name)142 else:143 raise TypeError(144 "Invalid test_suite, %r, in %s"145 % (suite, module_name)146 )147 except KeyboardInterrupt:148 raise149 except:150 suite = StartUpFailure(151 options, module_name, sys.exc_info()[:2]+(None,))152 yield suite153 break154def find_test_files(options):155 found = {}156 for f, package in find_test_files_(options):157 if f not in found:158 found[f] = 1159 yield f, package160def find_test_files_(options):161 tests_pattern = options.tests_pattern162 test_file_pattern = options.test_file_pattern163 # If options.usecompiled, we can accept .pyc or .pyo files instead164 # of .py files. We'd rather use a .py file if one exists. `root2ext`165 # maps a test file path, sans extension, to the path with the best166 # extension found (.py if it exists, else .pyc or .pyo).167 # Note that "py" < "pyc" < "pyo", so if more than one extension is168 # found, the lexicographically smaller one is best.169 # Found a new test file, in directory `dirname`. `noext` is the170 # file name without an extension, and `withext` is the file name171 # with its extension.172 def update_root2ext(dirname, noext, withext):173 key = os.path.join(dirname, noext)174 new = os.path.join(dirname, withext)175 if key in root2ext:176 root2ext[key] = min(root2ext[key], new)177 else:178 root2ext[key] = new179 for (p, package) in test_dirs(options, {}):180 for dirname, dirs, files in walk_with_symlinks(options, p):181 if dirname != p and not contains_init_py(options, files):182 # This is not a plausible test directory. Avoid descending183 # further.184 del dirs[:]185 continue186 root2ext = {}187 dirs[:] = filter(identifier, dirs)188 d = os.path.split(dirname)[1]189 if tests_pattern(d) and contains_init_py(options, files):190 # tests directory191 for file in files:192 noext = strip_py_ext(options, file)193 if noext and test_file_pattern(noext):194 update_root2ext(dirname, noext, file)195 for file in files:196 noext = strip_py_ext(options, file)197 if noext and tests_pattern(noext):198 update_root2ext(dirname, noext, file)199 winners = root2ext.values()200 winners.sort()201 for file in winners:202 yield file, package203def strip_py_ext(options, path):204 """Return path without its .py (or .pyc or .pyo) extension, or None.205 If options.usecompiled is false:206 If path ends with ".py", the path without the extension is returned.207 Else None is returned.208 If options.usecompiled is true:209 If Python is running with -O, a .pyo extension is also accepted.210 If Python is running without -O, a .pyc extension is also accepted.211 """212 if path.endswith(".py"):213 return path[:-3]214 if options.usecompiled:215 if __debug__:216 # Python is running without -O.217 ext = ".pyc"...

Full Screen

Full Screen

moduleimport.py

Source:moduleimport.py Github

copy

Full Screen

...10import re11import imp12import warnings13from lemoncheesecake.exceptions import serialize_current_exception, ModuleImportError14def strip_py_ext(filename):15 return re.sub(r"\.py$", "", filename)16def get_py_files_from_dir(dir):17 return \18 sorted(19 filter(20 lambda f: not os.path.basename(f).startswith("__"), glob.glob(os.path.join(dir, "*.py"))21 )22 )23def get_matching_files(patterns, excluding=[]):24 if type(patterns) not in (list, tuple):25 patterns = [patterns]26 if type(excluding) not in (list, tuple):27 excluding = [excluding]28 files = []29 for pattern in patterns:30 files.extend(glob.glob(pattern))31 if excluding:32 tmp = files[:] # iterate on copy to be able to alter files33 for file in tmp:34 for excluded in excluding:35 if fnmatch.fnmatch(file, excluded):36 files.remove(file)37 break38 return sorted(files)39def import_module(mod_filename):40 mod_dir = osp.dirname(mod_filename)41 mod_name = strip_py_ext(osp.basename(mod_filename))42 ###43 # Find module44 ###45 sys.path.insert(0, mod_dir)46 try:47 with warnings.catch_warnings():48 # would raise a warning since module's directory does not need to have a __init__.py49 warnings.simplefilter("ignore", ImportWarning)50 fh, path, description = imp.find_module(mod_name)51 except ImportError:52 raise ModuleImportError(53 "Cannot find module '%s': %s" % (mod_filename, serialize_current_exception(show_stacktrace=True))54 )55 finally:...

Full Screen

Full Screen

setup.py

Source:setup.py Github

copy

Full Screen

...6f = open('README.md')7long_description = f.read().strip()8f.close()9# idea from http://stackoverflow.com/a/11400431/213942010class strip_py_ext(distutils.command.install_scripts.install_scripts):11 def run(self):12 distutils.command.install_scripts.install_scripts.run(self)13 for script in self.get_outputs():14 if script.endswith(".py"):15 shutil.move(script, script[:-3])16setup(17 name = "gstatus",18 version= version.VERSION,19 description= "Show the health of the components in a glusterfs Trusted Storage Pool",20 long_description = long_description,21 author = "Paul Cuzner",22 author_email = "pcuzner@redhat.com",23 url = "https://github.com/gluster/gstatus",24 license = "GPLv3",...

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