Best Python code snippet using autotest_python
test2_dict_interface.py
Source:test2_dict_interface.py
...407 self.assertTrue(operator.lt(oc.viewkeys(), ('a', 'f')))408 self.assertTrue(operator.le(oc.viewkeys(), ('a', 'f')))409 self.assertFalse(operator.gt(oc.viewkeys(), ('a', 'f')))410 self.assertFalse(operator.ge(oc.viewkeys(), ('a', 'f')))411 v = oc.viewvalues() | {1, 9 }412 self.assertEqual(v, {1,2,3,4,5,9})413 self.assertIsInstance(v, set)414 self.assertRaises(TypeError, operator.or_, oc.viewvalues(), (1, 9))415 self.assertRaises(TypeError, operator.or_, (1, 9), oc.viewvalues())416 v = oc.viewvalues() & {1, 9 }417 self.assertEqual(v, {1})418 self.assertIsInstance(v, set)419 self.assertRaises(TypeError, operator.and_, oc.viewvalues(), (1, 9))420 self.assertRaises(TypeError, operator.and_, (1, 9), oc.viewvalues())421 v = oc.viewvalues() ^ {1, 9 }422 self.assertEqual(v, {2, 3, 4, 5, 9})423 self.assertIsInstance(v, set)424 self.assertRaises(TypeError, operator.xor, oc.viewvalues(), (1, 9))425 self.assertRaises(TypeError, operator.xor, (1, 9), oc.viewvalues())426 v = oc.viewvalues() - {1, 9 }427 self.assertEqual(v, {2,3,4,5})428 self.assertIsInstance(v, set)429 self.assertRaises(TypeError, operator.sub, oc.viewvalues(), (1, 9))430 self.assertRaises(TypeError, operator.sub, (1, 9), oc.viewvalues())431 self.assertTrue(operator.lt(oc.viewvalues(), (1, 9)))432 self.assertTrue(operator.le(oc.viewvalues(), (1, 9)))433 self.assertFalse(operator.gt(oc.viewvalues(), (1, 9)))434 self.assertFalse(operator.ge(oc.viewvalues(), (1, 9)))435 v = oc.viewitems() | {('a', 1), ('f', 9) }436 self.assertEqual(v, {('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 9)})437 self.assertIsInstance(v, set)438 self.assertRaises(TypeError, operator.or_, oc.viewitems(), (('a', 1), ('f', 9)))439 self.assertRaises(TypeError, operator.or_, (1, 9), oc.viewitems())440 v = oc.viewitems() & {('a',1), ('f',9)}441 self.assertEqual(v, {('a', 1)})442 self.assertIsInstance(v, set)443 self.assertRaises(TypeError, operator.and_, oc.viewitems(), (('a', 1), ('f', 9)))444 self.assertRaises(TypeError, operator.and_, (('a', 1), ('f', 9)), oc.viewitems())445 v = oc.viewitems() ^ {('a',1), ('f',9)}446 self.assertEqual(v, {('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 9)})447 self.assertIsInstance(v, set)448 self.assertRaises(TypeError, operator.xor, oc.viewitems(), (('a', 1), ('f', 9)))...
simulation.py
Source:simulation.py
...133 # initialize random streams134 internal_state.seed = self._seedFromName(state_name)135 internal_state.randomState = np.random.RandomState(seed=internal_state.seed)136 internal_state.initialize(self, sim_data)137 for external_state in six.viewvalues(self.external_states):138 external_state.initialize(self, sim_data, self._timeline)139 for process_name, process in six.viewitems(self.processes):140 # initialize random streams141 process.seed = self._seedFromName(process_name)142 process.randomState = np.random.RandomState(seed=process.seed)143 process.initialize(self, sim_data)144 for listener in six.viewvalues(self.listeners):145 listener.initialize(self, sim_data)146 for hook in six.viewvalues(self.hooks):147 hook.initialize(self, sim_data)148 for internal_state in six.viewvalues(self.internal_states):149 internal_state.allocate()150 for listener in six.viewvalues(self.listeners):151 listener.allocate()152 self._initialConditionsFunction(sim_data)153 self._timeTotal = self.initialTime()154 for hook in six.viewvalues(self.hooks):155 hook.postCalcInitialConditions(self)156 # Make permanent reference to evaluation time listener157 self._eval_time = self.listeners["EvaluationTime"]158 # Perform initial mass calculations159 for state in six.viewvalues(self.internal_states):160 state.calculateMass()161 # Update environment state according to the current time in time series162 for external_state in six.viewvalues(self.external_states):163 external_state.update()164 # Perform initial listener update165 for listener in six.viewvalues(self.listeners):166 listener.initialUpdate()167 # Start logging168 for logger in six.viewvalues(self.loggers):169 logger.initialize(self)170 def _initLoggers(self):171 self.loggers = collections.OrderedDict()172 if self._logToShell:173 self.loggers["Shell"] = wholecell.loggers.shell.Shell(174 self._shellColumnHeaders175 )176 if self._logToDisk:177 self.loggers["Disk"] = wholecell.loggers.disk.Disk(178 self._outputDir,179 self._overwriteExistingFiles,180 self._logToDiskEvery181 )182 # Run simulation183 def run(self):184 """185 Run the simulation for the time period specified in `self._lengthSec`186 and then clean up.187 """188 try:189 self.run_incremental(self._lengthSec + self.initialTime())190 if not self._raise_on_time_limit:191 self.cellCycleComplete()192 finally:193 self.finalize()194 if self._raise_on_time_limit and not self._cellCycleComplete:195 raise SimulationException('Simulation time limit reached without cell division')196 def run_incremental(self, run_until):197 """198 Run the simulation for a given amount of time.199 Args:200 run_until (float): absolute time to run the simulation until.201 """202 # Simulate203 while self.time() < run_until and not self._isDead:204 if self.time() > self.initialTime() + self._lengthSec:205 self.cellCycleComplete()206 if self._cellCycleComplete:207 self.finalize()208 break209 self._simulationStep += 1210 self._timeTotal += self._timeStepSec211 self._pre_evolve_state()212 for processes in self._processClasses:213 self._evolveState(processes)214 self._post_evolve_state()215 def run_for(self, run_for):216 self.run_incremental(self.time() + run_for)217 def finalize(self):218 """219 Clean up any details once the simulation has finished.220 Specifically, this calls `finalize` in all hooks,221 invokes the simulation's `_divideCellFunction` if the222 cell cycle has completed and then shuts down all loggers.223 """224 if not self._finalized:225 # Run post-simulation hooks226 for hook in six.viewvalues(self.hooks):227 hook.finalize(self)228 # Divide mother into daughter cells229 if self._cellCycleComplete:230 self.daughter_paths = self._divideCellFunction()231 # Finish logging232 for logger in six.viewvalues(self.loggers):233 logger.finalize(self)234 self._finalized = True235 def _pre_evolve_state(self):236 self._adjustTimeStep()237 # Run pre-evolveState hooks238 for hook in six.viewvalues(self.hooks):239 hook.preEvolveState(self)240 # Reset process mass difference arrays241 for state in six.viewvalues(self.internal_states):242 state.reset_process_mass_diffs()243 # Reset values in evaluationTime listener244 self._eval_time.reset_evaluation_times()245 # Calculate temporal evolution246 def _evolveState(self, processes):247 # Update queries248 # TODO: context manager/function calls for this logic?249 for i, state in enumerate(six.viewvalues(self.internal_states)):250 t = monotonic_seconds()251 state.updateQueries()252 self._eval_time.update_queries_times[i] += monotonic_seconds() - t253 # Calculate requests254 for i, process in enumerate(six.viewvalues(self.processes)):255 if process.__class__ in processes:256 t = monotonic_seconds()257 process.calculateRequest()258 self._eval_time.calculate_request_times[i] += monotonic_seconds() - t259 # Partition states among processes260 for i, state in enumerate(six.viewvalues(self.internal_states)):261 t = monotonic_seconds()262 state.partition(processes)263 self._eval_time.partition_times[i] += monotonic_seconds() - t264 # Simulate submodels265 for i, process in enumerate(six.viewvalues(self.processes)):266 if process.__class__ in processes:267 t = monotonic_seconds()268 process.evolveState()269 self._eval_time.evolve_state_times[i] += monotonic_seconds() - t270 # Check that timestep length was short enough271 for process_name, process in six.viewitems(self.processes):272 if process_name in processes and not process.wasTimeStepShortEnough():273 raise Exception("The timestep (%.3f) was too long at step %i, failed on process %s" % (self._timeStepSec, self.simulationStep(), str(process.name())))274 # Merge state275 for i, state in enumerate(six.viewvalues(self.internal_states)):276 t = monotonic_seconds()277 state.merge(processes)278 self._eval_time.merge_times[i] += monotonic_seconds() - t279 # update environment state280 for state in six.viewvalues(self.external_states):281 state.update()282 def _post_evolve_state(self):283 # Calculate mass of all molecules after evolution284 for i, state in enumerate(six.viewvalues(self.internal_states)):285 t = monotonic_seconds()286 state.calculateMass()287 self._eval_time.calculate_mass_times[i] = monotonic_seconds() - t288 # Update listeners289 for i, listener in enumerate(six.viewvalues(self.listeners)):290 t = monotonic_seconds()291 listener.update()292 self._eval_time.update_times[i] = monotonic_seconds() - t293 # Run post-evolveState hooks294 for hook in six.viewvalues(self.hooks):295 hook.postEvolveState(self)296 # Append loggers297 for i, logger in enumerate(six.viewvalues(self.loggers)):298 t = monotonic_seconds()299 logger.append(self)300 # Note: these values are written at the next timestep301 self._eval_time.append_times[i] = monotonic_seconds() - t302 def _seedFromName(self, name):303 return binascii.crc32(name.encode('utf-8'), self._seed) & 0xffffffff304 def initialTime(self):305 return self._initialTime306 # Save to disk307 def tableCreate(self, tableWriter):308 tableWriter.writeAttributes(309 states = list(self.internal_states.keys()),310 processes = list(self.processes.keys())311 )312 def tableAppend(self, tableWriter):313 tableWriter.append(314 time = self.time(),315 timeStepSec = self.timeStepSec()316 )317 def time(self):318 return self._timeTotal319 def simulationStep(self):320 return self._simulationStep321 def timeStepSec(self):322 return self._timeStepSec323 def lengthSec(self):324 return self._lengthSec325 def cellCycleComplete(self):326 self._cellCycleComplete = True327 def get_sim_data(self):328 return self._simData329 def _adjustTimeStep(self):330 # Adjust timestep if needed or at a frequency of updateTimeStepFreq regardless331 validTimeSteps = self._maxTimeStep * np.ones(len(self.processes))332 resetTimeStep = False333 for i, process in enumerate(six.viewvalues(self.processes)):334 if not process.isTimeStepShortEnough(self._timeStepSec, self._timeStepSafetyFraction) or self.simulationStep() % self._updateTimeStepFreq == 0:335 validTimeSteps[i] = self._findTimeStep(0., self._maxTimeStep, process.isTimeStepShortEnough)336 resetTimeStep = True337 if resetTimeStep:338 self._timeStepSec = validTimeSteps.min()339 def _findTimeStep(self, minTimeStep, maxTimeStep, checkerFunction):340 N = 10000341 candidateTimeStep = maxTimeStep342 for i in range(N):343 if checkerFunction(candidateTimeStep, self._timeStepSafetyFraction):344 minTimeStep = candidateTimeStep345 if (maxTimeStep - minTimeStep) / minTimeStep <= 1e-2:346 break347 else:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!