def with_args(self, **kwargs): return type(self)( minimum=util.format_string(self._minimum, kwargs), maximum=util.format_string(self._maximum, kwargs), marginal_minimum=util.format_string(self._marginal_minimum, kwargs), marginal_maximum=util.format_string(self._marginal_maximum, kwargs), type=self._type, )
def with_args(self, **kwargs): """String substitution for names and docstrings.""" validators = [ validator.with_args(**kwargs) if hasattr(validator, 'with_args') else validator for validator in self.validators ] return mutablerecords.CopyRecord( self, name=util.format_string(self.name, kwargs), docstring=util.format_string(self.docstring, kwargs), validators=validators, )
def with_plugs(self: SequenceClassT, **subplugs: Type[base_plugs.BasePlug]) -> SequenceClassT: """Substitute plugs for placeholders for this phase, error on unknowns.""" return attr.evolve( self, nodes=tuple(n.with_plugs(**subplugs) for n in self.nodes), name=util.format_string(self.name, subplugs))
def with_args(self, **kwargs: Any) -> 'PhaseGroup': """Send known keyword-arguments to each contained phase the when called.""" return attr.evolve( self, setup=self.setup.with_args(**kwargs) if self.setup else None, main=self.main.with_args(**kwargs) if self.main else None, teardown=self.teardown.with_args(**kwargs) if self.teardown else None, name=util.format_string(self.name, kwargs))
def with_args(self, **kwargs: Any) -> 'Measurement': """String substitution for names and docstrings.""" new_validators = [ v.with_args(**kwargs) if hasattr(v, 'with_args') else v for v in self.validators ] new_conditional_validators = [ cv.with_args(**kwargs) for cv in self.conditional_validators ] return data.attr_copy( self, name=util.format_string(self.name, kwargs), docstring=util.format_string(self.docstring, kwargs), validators=new_validators, conditional_validators=new_conditional_validators, cached=None, )
def __call__(self, test_record): record_dict = data.convert_to_base_types( test_record, json_safe=(not self.allow_nan)) if id_pattern is not None: record_dict['_id'] = format_string(self.id_pattern, record_dict) with self.db_client_context as client: db = client.get_database(self.db_name) db.create_document(test_record)
def with_plugs(self, **subplugs: Type[base_plugs.BasePlug]) -> 'PhaseGroup': """Substitute only known plugs for placeholders for each contained phase.""" return PhaseGroup( setup=self.setup.with_plugs(**subplugs) if self.setup else None, main=self.main.with_plugs(**subplugs) if self.main else None, teardown=self.teardown.with_plugs( **subplugs) if self.teardown else None, name=util.format_string(self.name, subplugs))
def with_args(self, **kwargs): """String substitution for names and docstrings.""" new_validators = [ v.with_args(**kwargs) if hasattr(v, 'with_args') else v for v in self.validators ] new_conditional_validators = [ cv.with_args(**kwargs) for cv in self.conditional_validators ] return mutablerecords.CopyRecord( self, name=util.format_string(self.name, kwargs), docstring=util.format_string(self.docstring, kwargs), validators=new_validators, conditional_validators=new_conditional_validators, _cached=None, )
def create_file_name(self, test_rec: test_record.TestRecord) -> Text: """Use filename_pattern and test_rec to create filename.""" if self.filename_pattern is None: raise ValueError( 'filename_pattern must be string or callable to create file name.' ) # Ignore keys for the log filename to not convert larger data structures. record_dict = data.convert_to_base_types(test_rec, ignore_keys=('code_info', 'phases', 'log_records')) return typing.cast( Text, util.format_string(self.filename_pattern, record_dict))
def create_file_name(self, test_record): """Use filename_pattern and test_record to create filename.""" # Ignore keys for the log filename to not convert larger data structures. record_dict = data.convert_to_base_types(test_record, ignore_keys=('code_info', 'phases', 'log_records')) if self._pattern_formattable: return util.format_string(self.filename_pattern, record_dict) else: raise ValueError( 'filename_pattern must be string or callable to create file name' )
def open_output_file(self, test_record): """Open file based on pattern.""" record_dict = data.convert_to_base_types(test_record) pattern = self.filename_pattern if isinstance(pattern, basestring) or callable(pattern): output_file = self.open_file(util.format_string(pattern, **record_dict)) try: yield output_file finally: output_file.close() elif hasattr(self.filename_pattern, 'write'): yield self.filename_pattern else: raise ValueError( 'filename_pattern must be string, callable, or File-like object')
def open_output_file(self, test_record): """Open file based on pattern.""" # Ignore keys for the log filename to not convert larger data structures. record_dict = data.convert_to_base_types( test_record, ignore_keys=('code_info', 'phases', 'log_records')) pattern = self.filename_pattern if isinstance(pattern, str) or callable(pattern): output_file = self.open_file(util.format_string(pattern, record_dict)) try: yield output_file finally: output_file.close() elif hasattr(self.filename_pattern, 'write'): yield self.filename_pattern else: raise ValueError( 'filename_pattern must be string, callable, or File-like object')
def open_output_file(self, test_record): """Open file based on pattern.""" # Ignore keys for the log filename to not convert larger data structures. record_dict = data.convert_to_base_types( test_record, ignore_keys=('code_info', 'phases', 'log_records')) pattern = self.filename_pattern if isinstance(pattern, six.string_types) or callable(pattern): output_file = self.open_file(util.format_string(pattern, record_dict)) try: yield output_file finally: output_file.close() elif hasattr(self.filename_pattern, 'write'): yield self.filename_pattern else: raise ValueError( 'filename_pattern must be string, callable, or File-like object')
def format_strings(self, **kwargs): """String substitution for names and docstrings.""" return mutablerecords.CopyRecord( self, name=util.format_string(self.name, kwargs), docstring=util.format_string(self.docstring, kwargs))
def format_strings(self, **kwargs): """String substitution of name.""" return mutablerecords.CopyRecord( self, name=util.format_string(self.name, kwargs))
def with_args(self: SequenceClassT, **kwargs: Any) -> SequenceClassT: """Send these keyword-arguments when phases are called.""" return attr.evolve( self, nodes=tuple(n.with_args(**kwargs) for n in self.nodes), name=util.format_string(self.name, kwargs))
def format_strings(self, **kwargs): """String substitution of name.""" return mutablerecords.CopyRecord( self, name=util.format_string(self.name, **kwargs))
def with_plugs(self, **subplugs: Any) -> 'Checkpoint': return data.attr_copy(self, name=util.format_string(self.name, subplugs))
def with_args(self, **kwargs: Any) -> 'Checkpoint': return data.attr_copy(self, name=util.format_string(self.name, kwargs))
def format_strings(self, **kwargs: Any) -> 'PhaseOptions': """String substitution of name.""" return data.attr_copy(self, name=util.format_string(self.name, kwargs))
def format_strings(self, **kwargs): """String substitution for names and docstrings.""" return mutablerecords.CopyRecord( self, name=util.format_string(self.name, **kwargs), docstring=util.format_string(self.docstring, **kwargs))
def with_args(self, **kwargs): return type(self)( minimum=util.format_string(self.minimum, kwargs), maximum=util.format_string(self.maximum, kwargs), type=self._type, )