How to use _load_from_file method in lisa

Best Python code snippet using lisa_python

context.py

Source:context.py Github

copy

Full Screen

...10 self.path = path11 self._data = {}12 self._defaults = {}13 self._mtime = 014 self._load_from_file()15 def _load_from_file(self):16 mtime = os.path.getmtime(self.path)17 if mtime - (self._mtime or 0) < 0.001:18 return19 data = yaml.safe_load(open(self.path))20 if not isinstance(data, dict):21 raise TypeError('the contextmap file is not dict-like')22 data.update(self._defaults)23 self._data = data24 self._mtime = mtime25 def get(self, key, default=None):26 return self._data.get(key, default)27 def pop(self, key, default=None):28 return self._data.pop(key, default)29 def get_keys(self):30 self._load_from_file()31 return list(self._data)32 def setdefault(self, key, default=None):33 try:34 return self._data[key]35 except LookupError:36 return self._defaults.setdefault(key, default)37class RealContextFile(ContextFile):38 def __init__(self, path, ttl=60):39 super(ContextFile, self).__init__(path)40 self._xtime = 041 self.ttl = ttl42 def get(self, key, default=None):43 current_time = time.time()44 # expired45 if current_time > self._xtime:46 self._load_from_file()47 self._xtime = current_time + self.ttl48 return self._data.get(key, default)49 def setdefault(self, key, default=None):50 return self._data.setdefault(key, default)51class ContextDirectory(object):52 def __init__(self, dir_path):53 if not os.path.isdir(dir_path):54 raise ValueError('requires a directory')55 self._cache = {}56 self._mtime = {}57 self.path = dir_path58 def _load_from_file(self, key):59 """60 Update _mtime and _cache if yaml.safe_load() is called.61 """62 path = join(self.path, key + '.yml')63 if not os.path.isfile(path):64 return65 mtime = os.path.getmtime(path)66 # avoid float equality test67 if mtime - self._mtime.get(key, 0) < 0.001:68 try:69 return self._cache[key]70 except LookupError:71 pass72 section = yaml.safe_load(open(path))73 self._mtime[key] = mtime74 self._cache[key] = section75 return section76 def setdefault(self, key, default=None):77 # only set default when key is not available in FS78 return self._cache.setdefault(key, self.get(key, default))79 def get(self, key, default=None):80 try:81 return self._cache[key]82 except LookupError:83 return self._load_from_file(key) or default84 def get_keys(self):85 _keys = []86 for filename in os.listdir(self.path):87 name, ext = os.path.splitext(filename)88 if ext == '.yml':89 _keys.append(name)90 return _keys91class RealContextDirectory(ContextDirectory):92 def __init__(self, dir_path, ttl=60):93 super(RealContextDirectory, self).__init__(dir_path)94 self._xtime = {}95 self.ttl = ttl96 def get(self, key, default=None):97 """98 Update _xtime if _load_from_file() is called and ttl available.99 Do NOT touch _cache and _mtime in this method;100 it is the job of _load_from_file.101 """102 current_time = time.time()103 expire_time = self._xtime.get(key, 0)104 # expired105 if current_time > expire_time:106 section = self._load_from_file(key)107 self._xtime[key] = current_time + self.ttl108 return section109 return super(RealContextDirectory, self).get(key, default)110 def setdefault(self, key, default=None):111 section = self._cache.setdefault(key, self.get(key, default))112 self._xtime.setdefault(key, float('inf'))113 return section114def context_load(path, ttl=None):115 if os.path.isdir(path):116 if ttl is None:117 return ContextDirectory(path)118 else:119 return RealContextDirectory(path, ttl)120 elif os.path.isfile(path):...

Full Screen

Full Screen

coeffs.py

Source:coeffs.py Github

copy

Full Screen

...8 _HAVE_PYWT = True9except ImportError:10 _HAVE_PYWT = False11COEFF_CACHE = {}12def _load_from_file(basename, varnames):13 try:14 mat = COEFF_CACHE[basename]15 except KeyError:16 with resource_stream('pytorch_wavelets.dtcwt.data', basename + '.npz') as f:17 mat = dict(load(f))18 COEFF_CACHE[basename] = mat19 try:20 return tuple(mat[k] for k in varnames)21 except KeyError:22 raise ValueError(23 'Wavelet does not define ({0}) coefficients'.format(24 ', '.join(varnames)))25def biort(name):26 """ Deprecated. Use :py::func:`pytorch_wavelets.dtcwt.coeffs.level1`27 Instead28 """29 return level1(name, compact=True)30def level1(name, compact=False):31 """Load level 1 wavelet by name.32 :param name: a string specifying the wavelet family name33 :returns: a tuple of vectors giving filter coefficients34 ============= ============================================35 Name Wavelet36 ============= ============================================37 antonini Antonini 9,7 tap filters.38 farras Farras 8,8 tap filters39 legall LeGall 5,3 tap filters.40 near_sym_a Near-Symmetric 5,7 tap filters.41 near_sym_b Near-Symmetric 13,19 tap filters.42 near_sym_b_bp Near-Symmetric 13,19 tap filters + BP filter43 ============= ============================================44 Return a tuple whose elements are a vector specifying the h0o, g0o, h1o and45 g1o coefficients.46 See :ref:`rot-symm-wavelets` for an explanation of the ``near_sym_b_bp``47 wavelet filters.48 :raises IOError: if name does not correspond to a set of wavelets known to49 the library.50 :raises ValueError: if name doesn't specify51 :py:func:`pytorch_wavelets.dtcwt.coeffs.qshift` wavelet.52 """53 if compact:54 if name == 'near_sym_b_bp':55 return _load_from_file(name, ('h0o', 'g0o', 'h1o', 'g1o', 'h2o', 'g2o'))56 else:57 return _load_from_file(name, ('h0o', 'g0o', 'h1o', 'g1o'))58 else:59 return _load_from_file(name, ('h0a', 'h0b', 'g0a', 'g0b', 'h1a', 'h1b',60 'g1a', 'g1b'))61def qshift(name):62 """Load level >=2 wavelet by name,63 :param name: a string specifying the wavelet family name64 :returns: a tuple of vectors giving filter coefficients65 ============ ============================================66 Name Wavelet67 ============ ============================================68 qshift_06 Quarter Sample Shift Orthogonal (Q-Shift) 10,10 tap filters,69 (only 6,6 non-zero taps).70 qshift_a Q-shift 10,10 tap filters,71 (with 10,10 non-zero taps, unlike qshift_06).72 qshift_b Q-Shift 14,14 tap filters.73 qshift_c Q-Shift 16,16 tap filters.74 qshift_d Q-Shift 18,18 tap filters.75 qshift_b_bp Q-Shift 18,18 tap filters + BP76 ============ ============================================77 Return a tuple whose elements are a vector specifying the h0a, h0b, g0a,78 g0b, h1a, h1b, g1a and g1b coefficients.79 See :ref:`rot-symm-wavelets` for an explanation of the ``qshift_b_bp``80 wavelet filters.81 :raises IOError: if name does not correspond to a set of wavelets known to82 the library.83 :raises ValueError: if name doesn't specify a84 :py:func:`pytorch_wavelets.dtcwt.coeffs.biort` wavelet.85 """86 if name == 'qshift_b_bp':87 return _load_from_file(name, ('h0a', 'h0b', 'g0a', 'g0b', 'h1a', 'h1b',88 'g1a', 'g1b', 'h2a', 'h2b', 'g2a','g2b'))89 else:90 return _load_from_file(name, ('h0a', 'h0b', 'g0a', 'g0b', 'h1a', 'h1b',91 'g1a', 'g1b'))92def pywt_coeffs(name):93 """ Wraps pywt Wavelet function. """94 if not _HAVE_PYWT:95 raise ImportError("Could not find PyWavelets module")96 return pywt.Wavelet(name)...

Full Screen

Full Screen

dice.py

Source:dice.py Github

copy

Full Screen

...5from math import sqrt67class Dice(Enum):8 @staticmethod9 def _load_from_file(path: str):10 dice = []11 path = os.path.join(os.path.dirname(os.path.realpath(__file__)), path)12 with open(path, 'r') as f:13 file_lines = f.readlines()14 for line in file_lines:15 faces = line.upper().strip().split(" ")16 # Validate faces17 # 1-3 letters are allowed18 face_lengths = [len(face) for face in faces]19 if min(face_lengths) == 0:20 raise ValueError("Cannot have empty faces")21 elif max(face_lengths) > 3:22 raise ValueError("Cannot have faces with more than 3 letters")23 ...

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