code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
date = self._confevent.get('confdate', {})
if len(date) > 0:
start = {k: int(v) for k, v in date['startdate'].items()}
end = {k: int(v) for k, v in date['enddate'].items()}
return ((start['@year'], start['@month'], start['@day']),
(end['@y... | def confdate(self) | Date range of the conference the abstract belongs to represented
by two tuples in the form (YYYY, MM, DD). | 2.561013 | 2.250582 | 1.137934 |
sponsors = chained_get(self._confevent, ['confsponsors', 'confsponsor'], [])
if len(sponsors) == 0:
return None
if isinstance(sponsors, list):
return [s['$'] for s in sponsors]
return sponsors | def confsponsor(self) | Sponsor(s) of the conference the abstract belongs to. | 5.525982 | 4.69786 | 1.176277 |
items = listify(chained_get(self._head, ['source', 'contributor-group'], []))
out = []
fields = 'given_name initials surname indexed_name role'
pers = namedtuple('Contributor', fields)
for item in items:
entry = item.get('contributor', {})
new = p... | def contributor_group(self) | List of namedtuples representing contributors compiled by Scopus,
in the form (given_name, initials, surname, indexed_name, role). | 4.762222 | 3.763628 | 1.265328 |
fields = 'surname initials organization country city_group'
auth = namedtuple('Correspondence', fields)
corr = self._head.get('correspondence')
if corr is None:
return None
aff = corr.get('affiliation', {})
try:
org = aff['organization']
... | def correspondence(self) | namedtuple representing the author to whom correspondence should
be addressed, in the form
(surname, initials, organization, country, city_group). | 4.181311 | 3.114815 | 1.342395 |
path = ['item', 'xocs:meta', 'xocs:funding-list', 'xocs:funding']
funds = listify(chained_get(self._json, path, []))
out = []
fund = namedtuple('Funding', 'agency string id acronym country')
for item in funds:
new = fund(agency=item.get('xocs:funding-agency')... | def funding(self) | List of namedtuples parsed funding information in the form
(agency string id acronym country). | 3.756857 | 3.3573 | 1.119011 |
isbns = listify(chained_get(self._head, ['source', 'isbn'], []))
if len(isbns) == 0:
return None
else:
return tuple((i['$'] for i in isbns)) | def isbn(self) | ISBNs belonging to publicationName as tuple of variying length,
(e.g. ISBN-10 or ISBN-13). | 7.942719 | 6.668188 | 1.191136 |
try:
terms = listify(self._json.get("idxterms", {}).get('mainterm', []))
except AttributeError: # idxterms is empty
return None
try:
return [d['$'] for d in terms]
except AttributeError:
return None | def idxterms(self) | List of index terms. | 7.685631 | 7.482924 | 1.027089 |
# Return information from FULL view, fall back to other views
full = chained_get(self._head, ['source', 'publisher', 'publishername'])
if full is None:
return self._json['coredata'].get('dc:publisher')
else:
return full | def publisher(self) | Name of the publisher of the abstract.
Note: Information provided in the FULL view of the article might be
more complete. | 18.503328 | 13.093613 | 1.413157 |
path = ['enhancement', 'sequencebanks', 'sequencebank']
items = listify(chained_get(self._head, path, []))
bank = namedtuple('Sequencebank', 'name sequence_number type')
out = []
for item in items:
numbers = listify(item['sequence-number'])
for nu... | def sequencebank(self) | List of namedtuples representing biological entities defined or
mentioned in the text, in the form (name, sequence_number, type). | 6.173831 | 5.336598 | 1.156885 |
area = namedtuple('Area', 'area abbreviation code')
path = ['subject-areas', 'subject-area']
out = [area(area=item['$'], abbreviation=item['@abbrev'],
code=item['@code'])
for item in listify(chained_get(self._json, path, []))]
return out or Non... | def subject_areas(self) | List of namedtuples containing subject areas of the article
in the form ().
Note: Requires the FULL view of the article. | 6.706419 | 6.622284 | 1.012705 |
if self.aggregationType != 'Journal':
raise ValueError('Only Journal articles supported.')
# Item key
year = self.coverDate[0:4]
first = self.title.split()[0].title()
last = self.title.split()[-1].title()
key = ''.join([self.authors[0].surname, year, ... | def get_bibtex(self) | Bibliographic entry in BibTeX format.
Raises
------
ValueError
If the item's aggregationType is not Journal. | 2.97895 | 2.724535 | 1.093379 |
# Author links
au_link = ('<a href="https://www.scopus.com/authid/detail.url'
'?origin=AuthorProfile&authorId={0}">{1}</a>')
if len(self.authors) > 1:
authors = u', '.join([au_link.format(a.auid, a.given_name +
... | def get_html(self) | Bibliographic entry in html format. | 2.807149 | 2.714015 | 1.034316 |
if len(self.authors) > 1:
authors = _list_authors(self.authors)
else:
a = self.authors
authors = ' '.join([a.given_name, a.surname])
if self.volume and self.issueIdentifier:
volissue = '\\textbf{{{}({})}}'.format(self.volume, self.issueIde... | def get_latex(self) | Bibliographic entry in LaTeX format. | 3.126633 | 2.970201 | 1.052667 |
if self.aggregationType != 'Journal':
raise ValueError('Only Journal articles supported.')
# Basic information
ris = "TY - JOUR\nTI - {title}\nJO - {jour}\nVL - {vol}\n"\
"DA - {date}\nPY - {year}\nSP - {pages}\n".format(
title=self.title... | def get_ris(self) | Bibliographic entry in RIS (Research Information System Format)
format for journal articles.
Raises
------
ValueError
If the item's aggregationType is not Journal. | 3.3485 | 2.92574 | 1.144497 |
cursor = "cursor" in params
if not cursor:
start = params["start"]
if n == 0:
return ""
_json = res.get('search-results', {}).get('entry', [])
# Download the remaining information in chunks
while n > 0:
n -= params["count"]
if cursor:
pointer = re... | def _parse(res, params, n, api, **kwds) | Auxiliary function to download results and parse json. | 4.492766 | 4.283396 | 1.048879 |
file_exists = exists(CONFIG_FILE)
if not file_exists:
# Set directories
config.add_section('Directories')
defaults = [
('AbstractRetrieval', expanduser('~/.scopus/abstract_retrieval')),
('AffiliationSearch', expanduser('~/.scopus/affiliation_search')),
... | def create_config() | Initiates process to generate configuration file. | 3.136842 | 3.070779 | 1.021513 |
out = []
order = 'eid surname initials givenname affiliation documents '\
'affiliation_id city country areas'
auth = namedtuple('Author', order)
for item in self._json:
name = item.get('preferred-name', {})
aff = item.get('affiliation-curr... | def authors(self) | A list of namedtuples storing author information,
where each namedtuple corresponds to one author.
The information in each namedtuple is (eid surname initials givenname
documents affiliation affiliation_id city country areas).
All entries are strings or None. Areas combines abbreviated... | 3.534884 | 2.767868 | 1.277114 |
try:
return "".join(container.find(xpath, ns).itertext())
except AttributeError:
return None | def get_encoded_text(container, xpath) | Return text for element at xpath in the container xml if it is there.
Parameters
----------
container : xml.etree.ElementTree.Element
The element to be searched in.
xpath : str
The path to be looked for.
Returns
-------
result : str | 4.506857 | 6.597882 | 0.683076 |
config = cosmic_ray.commands.new_config()
config_str = serialize_config(config)
with open(args['<config-file>'], mode='wt') as handle:
handle.write(config_str)
return ExitCode.OK | def handle_new_config(args) | usage: cosmic-ray new-config <config-file>
Create a new config file. | 5.653048 | 4.560646 | 1.239528 |
config_file = args['<config-file>']
config = load_config(config_file)
modules = set(cosmic_ray.modules.find_modules(Path(config['module-path'])))
log.info('Modules discovered: %s', [m for m in modules])
db_name = get_db_name(args['<session-file>'])
with use_db(db_name) as database:
... | def handle_init(args) | usage: cosmic-ray init <config-file> <session-file>
Initialize a mutation testing session from a configuration. This
primarily creates a session - a database of "work to be done" -
which describes all of the mutations and test runs that need to be
executed for a full mutation testing run. The configura... | 4.798303 | 4.866719 | 0.985942 |
session_file = get_db_name(args['<session-file>'])
with use_db(session_file) as database:
config = database.get_config()
print(serialize_config(config))
return ExitCode.OK | def handle_config(args) | usage: cosmic-ray config <session-file>
Show the configuration for in a session. | 6.330183 | 6.012747 | 1.052794 |
session_file = get_db_name(args.get('<session-file>'))
cosmic_ray.commands.execute(session_file)
return ExitCode.OK | def handle_exec(args) | usage: cosmic-ray exec <session-file>
Perform the remaining work to be done in the specified session.
This requires that the rest of your mutation testing
infrastructure (e.g. worker processes) are already running. | 15.262448 | 9.486357 | 1.608884 |
session_file = get_db_name(args['<session-file>'])
with use_db(session_file, WorkDB.Mode.open) as database:
for work_item, result in database.completed_work_items:
print(json.dumps((work_item, result), cls=WorkItemJsonEncoder))
for work_item in database.pending_work_items:
... | def handle_dump(args) | usage: cosmic-ray dump <session-file>
JSON dump of session data. This output is typically run through other
programs to produce reports.
Each line of output is a list with two elements: a WorkItem and a
WorkResult, both JSON-serialized. The WorkResult can be null, indicating a
WorkItem with no res... | 4.784995 | 4.354215 | 1.098934 |
assert args
print('\n'.join(cosmic_ray.plugins.operator_names()))
return ExitCode.OK | def handle_operators(args) | usage: {program} operators
List the available operator plugins. | 26.532423 | 18.39152 | 1.442644 |
assert args
print('\n'.join(cosmic_ray.plugins.execution_engine_names()))
return ExitCode.OK | def handle_execution_engines(args) | usage: {program} execution-engines
List the available execution-engine plugins. | 20.002863 | 15.760411 | 1.269184 |
assert args
print('\n'.join(cosmic_ray.plugins.interceptor_names()))
return ExitCode.OK | def handle_interceptors(args) | usage: {program} interceptors
List the available interceptor plugins. | 25.278656 | 23.008574 | 1.098662 |
python_version = args['--python-version']
if python_version is None:
python_version = "{}.{}".format(sys.version_info.major,
sys.version_info.minor)
apply_mutation(
Path(args['<module-path>']),
cosmic_ray.plugins.get_operator(args['<oper... | def handle_apply(args) | usage: {program} apply <module-path> <operator> <occurrence>
Apply the specified mutation to the files on disk. This is primarily a debugging
tool.
options:
--python-version=VERSION Python major.minor version (e.g. 3.6) of the code being mutated. | 5.213764 | 3.495201 | 1.491692 |
config = load_config(args.get('<config-file>'))
with open(os.devnull, 'w') as devnull:
with redirect_stdout(sys.stdout if args['--keep-stdout'] else devnull):
work_item = cosmic_ray.worker.worker(
Path(args['<module-path>']),
config.python_version, args[... | def handle_worker(args) | usage: {program} worker [options] <module-path> <operator> <occurrence> [<config-file>]
Run a worker process which performs a single mutation and test run.
Each worker does a minimal, isolated chunk of work: it mutates the
<occurence>-th instance of <operator> in <module-path>, runs the test
suite defi... | 6.240316 | 5.26868 | 1.184417 |
signal.signal(
signal.SIGINT,
lambda *args: sys.exit(_SIGNAL_EXIT_CODE_BASE + signal.SIGINT))
if hasattr(signal, 'SIGINFO'):
signal.signal(
getattr(signal, 'SIGINFO'),
lambda *args: report_progress(sys.stderr))
try:
return docopt_subcommands.mai... | def main(argv=None) | Invoke the cosmic ray evaluation.
:param argv: the command line arguments | 2.88658 | 2.942193 | 0.981098 |
def dec(cls):
name = '{}{}'.format(cls.__name__, suffix)
setattr(cls, '__name__', name)
return cls
return dec | def extend_name(suffix) | A factory for class decorators that modify the class name by appending some text to it.
Example:
@extend_name('_Foo')
class Class:
pass
assert Class.__name__ == 'Class_Foo' | 4.454808 | 3.959982 | 1.124957 |
assert index < len(OFFSETS), 'received count with no associated offset'
assert isinstance(node, parso.python.tree.Number)
val = eval(node.value) + OFFSETS[index] # pylint: disable=W0123
return parso.python.tree.Number(' ' + str(val), node.start_pos) | def mutate(self, node, index) | Modify the numeric value on `node`. | 7.121055 | 6.602042 | 1.078614 |
"Determines if from_op is allowed to be mutated to to_op."
# 'not' can only be removed but not replaced with
# '+', '-' or '~' b/c that may lead to strange results
if from_op is UnaryOperators.Not:
if to_op is not UnaryOperators.Nothing:
return True
# '+1' => '1' yields equivale... | def _prohibited(from_op, to_op) | Determines if from_op is allowed to be mutated to to_op. | 9.120406 | 7.741211 | 1.178163 |
try:
with _config_stream(filename) as handle:
filename = handle.name
return deserialize_config(handle.read())
except (OSError, toml.TomlDecodeError, UnicodeDecodeError) as exc:
raise ConfigError(
'Error loading configuration from {}'.format(filename)) fro... | def load_config(filename=None) | Load a configuration from a file or stdin.
If `filename` is `None` or "-", then configuration gets read from stdin.
Returns: A `ConfigDict`.
Raises: ConfigError: If there is an error loading the config. | 4.769496 | 4.749237 | 1.004266 |
if filename is None or filename == '-':
log.info('Reading config from stdin')
yield sys.stdin
else:
with open(filename, mode='rt') as handle:
log.info('Reading config from %r', filename)
yield handle | def _config_stream(filename) | Given a configuration's filename, this returns a stream from which a configuration can be read.
If `filename` is `None` or '-' then stream will be `sys.stdin`. Otherwise,
it's the open file handle for the filename. | 3.031498 | 3.151431 | 0.961944 |
"Get a sub-configuration."
d = self
for segment in segments:
try:
d = d[segment]
except KeyError:
return ConfigDict({})
return d | def sub(self, *segments) | Get a sub-configuration. | 5.551816 | 4.264309 | 1.301926 |
v = self.get('python-version', '')
if v == '':
v = "{}.{}".format(sys.version_info.major, sys.version_info.minor)
return v | def python_version(self) | Get the configured Python version.
If this is not set in the config, then it defaults to the version of the current runtime.
Returns: A string of the form "MAJOR.MINOR", e.g. "3.6". | 3.314642 | 3.105686 | 1.067282 |
assert index == 0
assert isinstance(node, ForStmt)
empty_list = parso.parse(' []')
node.children[3] = empty_list
return node | def mutate(self, node, index) | Modify the For loop to evaluate to None | 10.285126 | 8.551579 | 1.202716 |
sep = name.index('/')
provider_name = name[:sep]
operator_name = name[sep + 1:]
provider = OPERATOR_PROVIDERS[provider_name]
return provider[operator_name] | def get_operator(name) | Get an operator class from a provider plugin.
Attrs:
name: The name of the operator class.
Returns: The operator *class object* (i.e. not an instance). | 3.90586 | 4.559026 | 0.856731 |
return tuple('{}/{}'.format(provider_name, operator_name)
for provider_name, provider in OPERATOR_PROVIDERS.items()
for operator_name in provider) | def operator_names() | Get all operator names.
Returns: A sequence of operator names. | 5.272333 | 5.822773 | 0.905468 |
manager = driver.DriverManager(
namespace='cosmic_ray.execution_engines',
name=name,
invoke_on_load=True,
on_load_failure_callback=_log_extension_loading_failure,
)
return manager.driver | def get_execution_engine(name) | Get the execution engine by name. | 4.852743 | 4.57106 | 1.061623 |
database = WorkDB(path, mode)
try:
yield database
finally:
database.close() | def use_db(path, mode=WorkDB.Mode.create) | Open a DB in file `path` in mode `mode` as a context manager.
On exiting the context the DB will be automatically closed.
Args:
path: The path to the DB file.
mode: The mode in which to open the DB. See the `Mode` enum for
details.
Raises:
FileNotFoundError: If `mode` is `Mode.o... | 3.124723 | 7.220535 | 0.432755 |
with self._conn:
self._conn.execute("DELETE FROM config")
self._conn.execute('INSERT INTO config VALUES(?)',
(serialize_config(config),)) | def set_config(self, config) | Set (replace) the configuration for the session.
Args:
config: Configuration object | 4.476008 | 5.911553 | 0.757163 |
rows = list(self._conn.execute("SELECT * FROM config"))
if not rows:
raise ValueError("work-db has no config")
(config_str,) = rows[0]
return deserialize_config(config_str) | def get_config(self) | Get the work parameters (if set) for the session.
Returns: a Configuration object.
Raises:
ValueError: If is no config set for the session. | 7.349805 | 6.262355 | 1.173649 |
cur = self._conn.cursor()
rows = cur.execute("SELECT * FROM work_items")
for row in rows:
yield _row_to_work_item(row) | def work_items(self) | An iterable of all of WorkItems in the db.
This includes both WorkItems with and without results. | 3.787806 | 3.800637 | 0.996624 |
with self._conn:
self._conn.execute(
'''
INSERT INTO work_items
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
''', _work_item_to_row(work_item)) | def add_work_item(self, work_item) | Add a WorkItems.
Args:
work_item: A WorkItem. | 3.44615 | 3.756081 | 0.917486 |
with self._conn:
self._conn.execute('DELETE FROM results')
self._conn.execute('DELETE FROM work_items') | def clear(self) | Clear all work items from the session.
This removes any associated results as well. | 6.087817 | 4.733842 | 1.28602 |
"An iterable of all `(job-id, WorkResult)`s."
cur = self._conn.cursor()
rows = cur.execute("SELECT * FROM results")
for row in rows:
yield (row['job_id'], _row_to_work_result(row)) | def results(self) | An iterable of all `(job-id, WorkResult)`s. | 7.254137 | 3.525917 | 2.057376 |
with self._conn:
try:
self._conn.execute(
'''
REPLACE INTO results
VALUES (?, ?, ?, ?, ?)
''', _work_result_to_row(job_id, result))
except sqlite3.IntegrityError as exc:
... | def set_result(self, job_id, result) | Set the result for a job.
This will overwrite any existing results for the job.
Args:
job_id: The ID of the WorkItem to set the result for.
result: A WorkResult indicating the result of the job.
Raises:
KeyError: If there is no work-item with a matching job-id. | 4.329226 | 4.073356 | 1.062816 |
"Iterable of all pending work items."
pending = self._conn.execute(
"SELECT * FROM work_items WHERE job_id NOT IN (SELECT job_id FROM results)"
)
return (_row_to_work_item(p) for p in pending) | def pending_work_items(self) | Iterable of all pending work items. | 6.398195 | 6.120389 | 1.04539 |
"Iterable of `(work-item, result)`s for all completed items."
completed = self._conn.execute(
"SELECT * FROM work_items, results WHERE work_items.job_id == results.job_id"
)
return ((_row_to_work_item(result), _row_to_work_result(result))
for result in complet... | def completed_work_items(self) | Iterable of `(work-item, result)`s for all completed items. | 7.143277 | 4.71993 | 1.513429 |
arguments = docopt.docopt(report_xml.__doc__, version='cr-rate 1.0')
with use_db(arguments['<session-file>'], WorkDB.Mode.open) as db:
xml_elem = _create_xml_report(db)
xml_elem.write(
sys.stdout.buffer, encoding='utf-8', xml_declaration=True) | def report_xml() | cr-xml
Usage: cr-xml <session-file>
Print an XML formatted report of test results for continuos integration systems | 5.876061 | 5.824319 | 1.008884 |
try:
with use_db(db_name, mode=WorkDB.Mode.open) as work_db:
_update_progress(work_db)
config = work_db.get_config()
engine = get_execution_engine(config.execution_engine_name)
def on_task_complete(job_id, work_result):
work_db.set_result... | def execute(db_name) | Execute any pending work in the database stored in `db_name`,
recording the results.
This looks for any work in `db_name` which has no results, schedules it to
be executed, and records any results that arrive. | 4.541462 | 4.352834 | 1.043335 |
with module_path.open(mode='rt', encoding='utf-8') as handle:
source = handle.read()
return parso.parse(source, version=python_version) | def get_ast(module_path, python_version) | Get the AST for the code in a file.
Args:
module_path: pathlib.Path to the file containing the code.
python_version: Python version as a "MAJ.MIN" string.
Returns: The parso parse tree for the code in `module_path`. | 3.693149 | 3.863398 | 0.955933 |
"Determine if a node is the `None` keyword."
return isinstance(node, parso.python.tree.Keyword) and node.value == 'None' | def is_none(node) | Determine if a node is the `None` keyword. | 6.631915 | 4.90735 | 1.351425 |
"Walk a parse tree, calling visit for each node."
node = self.visit(node)
if node is None:
return None
if isinstance(node, parso.tree.BaseNode):
walked = map(self.walk, node.children)
node.children = [child for child in walked if child is not None]
... | def walk(self, node) | Walk a parse tree, calling visit for each node. | 3.471099 | 2.962515 | 1.171673 |
arguments = docopt.docopt(
format_survival_rate.__doc__, version='cr-rate 1.0')
with use_db(arguments['<session-file>'], WorkDB.Mode.open) as db:
rate = survival_rate(db)
print('{:.2f}'.format(rate)) | def format_survival_rate() | cr-rate
Usage: cr-rate <session-file>
Calculate the survival rate of a session. | 6.607499 | 5.970176 | 1.106751 |
kills = sum(r.is_killed for _, r in work_db.results)
num_results = work_db.num_results
if not num_results:
return 0
return (1 - kills / num_results) * 100 | def survival_rate(work_db) | Calcuate the survival rate for the results in a WorkDB. | 4.213411 | 3.603599 | 1.169223 |
arguments = docopt.docopt(report_html.__doc__, version='cr-rate 1.0')
with use_db(arguments['<session-file>'], WorkDB.Mode.open) as db:
doc = _generate_html_report(db)
print(doc.getvalue()) | def report_html() | cr-html
Usage: cr-html <session-file>
Print an HTML formatted report of test results. | 7.553302 | 7.154572 | 1.055731 |
arguments = docopt.docopt(report.__doc__, version='cr-format 0.1')
show_pending = arguments['--show-pending']
show_output = arguments['--show-output']
show_diff = arguments['--show-diff']
with use_db(arguments['<session-file>'], WorkDB.Mode.open) as db:
for work_item, result in db.com... | def report() | cr-report
Usage: cr-report [--show-output] [--show-diff] [--show-pending] <session-file>
Print a nicely formatted report of test results and some basic statistics.
options:
--show-output Display output of test executions
--show-diff Display diff of mutants
--show-pending Display results for incomp... | 2.958018 | 2.781037 | 1.063639 |
"Return True if a string is of the form <int>.<int>, False otherwise."
if not s:
return True
toks = s.split('.')
if len(toks) != 2:
return False
try:
int(toks[0])
int(toks[1])
except ValueError:
return False
return True | def _validate_python_version(s) | Return True if a string is of the form <int>.<int>, False otherwise. | 2.770365 | 2.027426 | 1.366445 |
config = ConfigDict()
config["module-path"] = qprompt.ask_str(
"Top-level module path",
blk=False,
vld=os.path.exists,
hlp=MODULE_PATH_HELP)
python_version = qprompt.ask_str(
'Python version (blank for auto detection)',
vld=_validate_python_version,
... | def new_config() | Prompt user for config variables and generate new config.
Returns: A new ConfigDict. | 4.413575 | 4.380712 | 1.007502 |
if module_path.is_file():
if module_path.suffix == '.py':
yield module_path
elif module_path.is_dir():
pyfiles = glob.glob('{}/**/*.py'.format(module_path), recursive=True)
yield from (Path(pyfile) for pyfile in pyfiles) | def find_modules(module_path) | Find all modules in the module (possibly package) represented by `module_path`.
Args:
module_path: A pathlib.Path to a Python package or module.
Returns: An iterable of paths Python modules (i.e. *py files). | 2.379414 | 2.342759 | 1.015646 |
operator_names = cosmic_ray.plugins.operator_names()
work_db.set_config(config=config)
work_db.clear()
for module_path in module_paths:
module_ast = get_ast(
module_path, python_version=config.python_version)
for op_name in operator_names:
operator = get_o... | def init(module_paths, work_db, config) | Clear and initialize a work-db with work items.
Any existing data in the work-db will be cleared and replaced with entirely
new work orders. In particular, this means that any results in the db are
removed.
Args:
module_paths: iterable of pathlib.Paths of modules to mutate.
work_db: A `Wor... | 5.36662 | 5.71097 | 0.939704 |
names = (name for name in interceptor_names() if name in enabled_interceptors)
for name in names:
interceptor = get_interceptor(name)
interceptor(work_db) | def apply_interceptors(work_db, enabled_interceptors) | Apply each registered interceptor to the WorkDB. | 3.865697 | 3.217517 | 1.201454 |
"Determine if a mutation from `from_op` to `to_op` is allowed given a particular `rhs` node."
if is_none(rhs):
return to_op in _RHS_IS_NONE_OPS.get(from_op, ())
if is_number(rhs):
return to_op in _RHS_IS_INTEGER_OPS
return True | def _allowed(to_op, from_op, rhs) | Determine if a mutation from `from_op` to `to_op` is allowed given a particular `rhs` node. | 5.744795 | 3.933632 | 1.46043 |
try:
operator_class = cosmic_ray.plugins.get_operator(operator_name)
operator = operator_class(python_version)
with cosmic_ray.mutating.use_mutation(module_path, operator,
occurrence) as (original_code,
... | def worker(module_path,
python_version,
operator_name,
occurrence,
test_command,
timeout) | Mutate the OCCURRENCE-th site for OPERATOR_NAME in MODULE_PATH, run the
tests, and report the results.
This is fundamentally the single-mutation-and-test-run process
implementation.
There are three high-level ways that a worker can finish. First, it could
fail exceptionally, meaning that some unca... | 3.499926 | 3.015322 | 1.160714 |
if stream is None:
stream = sys.stderr
for reporter in _reporters:
reporter(stream) | def report_progress(stream=None) | Report progress from any currently installed reporters.
Args:
stream: The text stream (default: sys.stderr) to which
progress will be reported. | 3.930055 | 4.739596 | 0.829196 |
def decorator(func): # pylint: disable=missing-docstring
@wraps(func)
def wrapper(*args, **kwargs): # pylint: disable=missing-docstring
with progress_reporter(reporter):
return func(*args, **kwargs)
return wrapper
return decorator | def reports_progress(reporter) | A decorator factory to mark functions which report progress.
Args:
reporter: A zero-argument callable to report progress.
The callable provided should have the means to both
retrieve and display current progress information. | 2.302939 | 2.404146 | 0.957903 |
"Get a set of tags for the current git repo."
result = [t.decode('ascii') for t in subprocess.check_output([
'git', 'tag'
]).split(b"\n")]
assert len(set(result)) == len(result)
return set(result) | def tags() | Get a set of tags for the current git repo. | 4.753138 | 3.551631 | 1.338297 |
"Create a git tag for `version` and push it to origin."
assert version not in tags()
git('config', 'user.name', 'Travis CI on behalf of Austin Bingham')
git('config', 'user.email', 'austin@sixty-north.com')
git('config', 'core.sshCommand', 'ssh -i deploy_key')
git(
'remote', 'add', 'ssh-... | def create_tag_and_push(version) | Create a git tag for `version` and push it to origin. | 4.644063 | 4.22332 | 1.099624 |
"Read the `(version-string, version-info)` from `version_file`."
vars = {}
with open(version_file) as f:
exec(f.read(), {}, vars)
return (vars['__version__'], vars['__version_info__']) | def read_version(version_file) | Read the `(version-string, version-info)` from `version_file`. | 4.182333 | 2.566371 | 1.629668 |
global _workspace
_ensure_workspace(config)
result = worker(
work_item.module_path,
config.python_version,
work_item.operator_name,
work_item.occurrence,
config.test_command,
config.timeout)
return work_item.job_id, result | def worker_task(work_item, config) | The celery task which performs a single mutation and runs a test suite.
This runs `cosmic-ray worker` in a subprocess and returns the results,
passing `config` to it via stdin.
Args:
work_item: A dict describing a WorkItem.
config: The configuration to use for the test execution.
Retu... | 7.460526 | 8.764114 | 0.851258 |
return celery.group(
worker_task.s(work_item, config)
for work_item in work_items
) | def execute_work_items(work_items, config) | Execute a suite of tests for a given set of work items.
Args:
work_items: An iterable of `work_db.WorkItem`s.
config: The configuration to use for the test execution.
Returns: An iterable of WorkItems. | 4.014021 | 7.352059 | 0.545972 |
workspace = ClonedWorkspace(clone_config)
original_dir = os.getcwd()
if chdir:
os.chdir(workspace.clone_dir)
try:
yield workspace
finally:
os.chdir(original_dir)
workspace.cleanup() | def cloned_workspace(clone_config, chdir=True) | Create a cloned workspace and yield it.
This creates a workspace for a with-block and cleans it up on exit. By
default, this will also change to the workspace's `clone_dir` for the
duration of the with-block.
Args:
clone_config: The execution engine configuration to use for the workspace.
... | 2.551385 | 3.278354 | 0.778252 |
log.info('Cloning git repo %s to %s', repo_uri, dest_path)
git.Repo.clone_from(repo_uri, dest_path, depth=1) | def clone_with_git(repo_uri, dest_path) | Create a clone by cloning a git repository.
Args:
repo_uri: The URI of the git repository to clone.
dest_path: The location to clone to. | 2.361352 | 2.855914 | 0.826829 |
log.info('Cloning directory tree %s to %s', src_path, dest_path)
shutil.copytree(src_path, dest_path) | def clone_with_copy(src_path, dest_path) | Clone a directory try by copying it.
Args:
src_path: The directory to be copied.
dest_path: The location to copy the directory to. | 3.176567 | 3.492516 | 0.909535 |
# NB: We had to create the because the venv modules wasn't doing what we
# needed. In particular, if we used it create a venv from an existing venv,
# it *always* created symlinks back to the original venv's python
# executables. Then, when you used those linked executables, you ended up
# inte... | def _build_env(venv_dir) | Create a new virtual environment in `venv_dir`.
This uses the base prefix of any virtual environment that you may be using
when you call this. | 5.138393 | 4.99473 | 1.028763 |
variables = {
'python-executable': str(self._venv_path / 'bin' / 'python')
}
return text.format(**variables) | def replace_variables(self, text) | Replace variable placeholders in `text` with values from the virtual env.
The variables are:
- {python-executable}
Args:
text: The text to do replacment int.
Returns: The text after replacement. | 6.645645 | 5.271367 | 1.260706 |
"Remove the directory containin the clone and virtual environment."
log.info('Removing temp dir %s', self._tempdir.name)
self._tempdir.cleanup() | def cleanup(self) | Remove the directory containin the clone and virtual environment. | 14.8943 | 5.053526 | 2.947308 |
"Get the WorkResult as a dict."
return {
'output': self.output,
'test_outcome': self.test_outcome,
'worker_outcome': self.worker_outcome,
'diff': self.diff,
} | def as_dict(self) | Get the WorkResult as a dict. | 5.871846 | 3.960953 | 1.482433 |
return {
'module_path': str(self.module_path),
'operator_name': self.operator_name,
'occurrence': self.occurrence,
'start_pos': self.start_pos,
'end_pos': self.end_pos,
'job_id': self.job_id,
} | def as_dict(self) | Get fields as a dict. | 2.927164 | 2.710007 | 1.080131 |
@lru_cache()
def file_contents(file_path):
"A simple cache of file contents."
with file_path.open(mode="rt") as handle:
return handle.readlines()
for item in work_db.work_items:
try:
repo = open_repository(item.module_path)
except ValueError:
... | def intercept(work_db) | Look for WorkItems in `work_db` that should not be mutated due to spor metadata.
For each WorkItem, find anchors for the item's file/line/columns. If an
anchor exists with metadata containing `{mutate: False}` then the WorkItem
is marked as SKIPPED. | 4.843074 | 3.947579 | 1.226847 |
offset = 0
for index, contents in enumerate(lines, 1):
if index == line:
return offset + col
offset += len(contents)
raise ValueError("Offset {}:{} not found".format(line, col)) | def _line_and_col_to_offset(lines, line, col) | Figure out the offset into a file for a particular line and col.
This can return offsets that don't actually exist in the file. If you
specify a line that exists and a col that is past the end of that line, this
will return a "fake" offset. This is to account for the fact that a
WorkItem's end_pos is o... | 4.235189 | 5.17757 | 0.817988 |
start_offset = _line_and_col_to_offset(lines, item.start_pos[0],
item.start_pos[1])
stop_offset = _line_and_col_to_offset(lines, item.end_pos[0],
item.end_pos[1])
width = stop_offset - start_offset
return start_of... | def _item_in_context(lines, item, context) | Determines if a WorkItem falls within an anchor.
This only returns True if a WorkItems start-/stop-pos range is *completely*
within an anchor, not just if it overalaps. | 3.050229 | 2.9497 | 1.034081 |
original_code, mutated_code = apply_mutation(module_path, operator,
occurrence)
try:
yield original_code, mutated_code
finally:
with module_path.open(mode='wt', encoding='utf-8') as handle:
handle.write(original_code)
... | def use_mutation(module_path, operator, occurrence) | A context manager that applies a mutation for the duration of a with-block.
This applies a mutation to a file on disk, and after the with-block it put the unmutated code
back in place.
Args:
module_path: The path to the module to mutate.
operator: The `Operator` instance to use.
oc... | 3.310359 | 3.360373 | 0.985116 |
module_ast = get_ast(module_path, python_version=operator.python_version)
original_code = module_ast.get_code()
visitor = MutationVisitor(occurrence, operator)
mutated_ast = visitor.walk(module_ast)
mutated_code = None
if visitor.mutation_applied:
mutated_code = mutated_ast.get_cod... | def apply_mutation(module_path, operator, occurrence) | Apply a specific mutation to a file on disk.
Args:
module_path: The path to the module to mutate.
operator: The `operator` instance to use.
occurrence: The occurrence of the operator to apply.
Returns: A `(unmutated-code, mutated-code)` tuple to the with-block. If there was
no ... | 2.935247 | 3.080809 | 0.952752 |
requirements_file = os.path.join(os.getcwd(), 'requirements.txt')
requirements = []
links=[]
try:
with open(requirements_file) as reqfile:
for line in reqfile.readlines():
line = line.strip()
if line.startswith('#'):
continue
... | def get_requirements() | Extract the list of requirements from our requirements.txt.
:rtype: 2-tuple
:returns: Two lists, the first is a list of requirements in the form of
pkgname==version. The second is a list of URIs or VCS checkout strings
which specify the dependency links for obtaining a copy of the
requi... | 4.717178 | 4.723527 | 0.998656 |
useparams = {}
for key, value in keyparams.items():
if value:
useparams.update({key: value})
batchfile = gpg.gen_key_input(separate_keyring=True,
save_batchfile=True,
**useparams)
log.info("Generated GnuPG batch... | def createBatchfile(keyparams=allparams) | Create the batchfile for our new key.
:params dict keyparams: A dictionary of arguments for creating the key. It
should probably be ``allparams``.
:rtype: str
:returns: A string containing the entire GnuPG batchfile. | 4.644077 | 5.028838 | 0.923489 |
key = gpg.gen_key(batchfile)
fingerprint = key.fingerprint
if not fingerprint:
log.error("Key creation seems to have failed: %s" % key.status)
return None, None
return key, fingerprint | def createKey(batchfile) | Create a new keypair from a **batchfile**.
Writes the new keys into keyrings named after ``NAME_EMAIL`` inside the
``NEWKEY_DIR``.
:params str batchfile: A GnuPG batchfile. See :func:`createBatchfile`. | 4.850117 | 6.607916 | 0.733986 |
if key.keyring:
gpg.keyring = key.keyring
if key.secring:
gpg.secring = key.secring
# Using '--fingerprint' twice will display subkey fingerprints too:
gpg.options = ['--fingerprint', '--fingerprint']
keylist = gpg.list_keys(secret=True)
# `result` is a `gnupg._parsers.Li... | def displayNewKey(key) | Use ``gnupg.GPG.list_keys()`` to display details of the new key. | 6.102716 | 5.16268 | 1.182083 |
log.info("Exporting key: %s" % fingerprint)
keyfn = os.path.join(gpg.homedir,
fingerprint + '-8192-bit-key') + os.path.extsep
pubkey = gpg.export_keys(fingerprint)
seckey = gpg.export_keys(fingerprint, secret=True)
subkey = gpg.export_keys(fingerprint, secret=True, su... | def exportNewKey(fingerprint) | Export the new keys into .asc files.
:param str fingerprint: A full key fingerprint. | 2.242553 | 2.307565 | 0.971827 |
protocols = ['hkp://', 'hkps://', 'http://', 'https://', 'ldap://',
'mailto:'] ## xxx feels like i´m forgetting one...
for proto in protocols:
if location.startswith(proto):
url = location.replace(proto, str())
host, slash, extra = url.partition('/')
... | def _check_keyserver(location) | Check that a given keyserver is a known protocol and does not contain
shell escape characters.
:param str location: A string containing the default keyserver. This
should contain the desired keyserver protocol which
is supported by the keyserver, for example, t... | 7.333069 | 6.710532 | 1.09277 |
if prefs is None: return
cipher = frozenset(['AES256', 'AES192', 'AES128',
'CAMELLIA256', 'CAMELLIA192',
'TWOFISH', '3DES'])
digest = frozenset(['SHA512', 'SHA384', 'SHA256', 'SHA224', 'RMD160',
'SHA1'])
compress = f... | def _check_preferences(prefs, pref_type=None) | Check cipher, digest, and compression preference settings.
MD5 is not allowed. This is `not 1994`__. SHA1 is allowed_ grudgingly_.
__ http://www.cs.colorado.edu/~jrblack/papers/md5e-full.pdf
.. _allowed: http://eprint.iacr.org/2008/469.pdf
.. _grudgingly: https://www.schneier.com/blog/archives/2012/10... | 2.549465 | 2.47338 | 1.030761 |
_unsafe = re.compile(r'[^\w@%+=:,./-]', 256)
try:
if len(_unsafe.findall(shell_input)) == 0:
return shell_input.strip()
else:
clean = "'" + shell_input.replace("'", "'\"'\"'") + "'"
return clean
except TypeError:
return None | def _fix_unsafe(shell_input) | Find characters used to escape from a string into a shell, and wrap them in
quotes if they exist. Regex pilfered from Python3 :mod:`shlex` module.
:param str shell_input: The input intended for the GnuPG process. | 3.581053 | 3.967129 | 0.902681 |
ret = '--' if add_prefix else ''
ret += input.replace('_', '-')
return ret | def _hyphenate(input, add_prefix=False) | Change underscores to hyphens so that object attributes can be easily
tranlated to GPG option names.
:param str input: The attribute to hyphenate.
:param bool add_prefix: If True, add leading hyphens to the input.
:rtype: str
:return: The ``input`` with underscores changed to hyphens. | 6.315956 | 8.834478 | 0.714921 |
gnupg_options = _get_all_gnupg_options()
allowed = _get_options_group("allowed")
## these are the allowed options we will handle so far, all others should
## be dropped. this dance is so that when new options are added later, we
## merely add the to the _allowed list, and the `` _allowed.issub... | def _is_allowed(input) | Check that an option or argument given to GPG is in the set of allowed
options, the latter being a strict subset of the set of all options known
to GPG.
:param str input: An input meant to be parsed as an option or flag to the
GnuPG process. Should be formatted the same as an option
... | 7.906628 | 6.695044 | 1.180967 |
if _util._py3k: return isinstance(thing, str)
else: return isinstance(thing, basestring) | def _is_string(thing) | Python character arrays are a mess.
If Python2, check if **thing** is an :obj:`unicode` or a :obj:`str`.
If Python3, check if **thing** is a :obj:`str`.
:param thing: The thing to check.
:returns: ``True`` if **thing** is a string according to whichever version
of Python we're running in... | 5.050672 | 6.08389 | 0.830171 |
if isinstance(arg_list, list):
for arg in arg_list:
safe_arg = _sanitise(arg)
if safe_arg != "":
yield safe_arg | def _sanitise_list(arg_list) | A generator for iterating through a list of gpg options and sanitising
them.
:param list arg_list: A list of options and flags for GnuPG.
:rtype: generator
:returns: A generator whose next() method returns each of the items in
``arg_list`` after calling ``_sanitise()`` with that item as a... | 3.026778 | 3.324845 | 0.910352 |
#: These expect a hexidecimal keyid as their argument, and can be parsed
#: with :func:`_is_hex`.
hex_options = frozenset(['--check-sigs',
'--default-key',
'--default-recipient',
'--delete-keys',
... | def _get_options_group(group=None) | Get a specific group of options which are allowed. | 4.244884 | 4.208883 | 1.008554 |
three_hundred_eighteen = ().split()
# These are extra options which only exist for GnuPG>=2.0.0
three_hundred_eighteen.append('--export-ownertrust')
three_hundred_eighteen.append('--import-ownertrust')
# These are extra options which only exist for GnuPG>=2.1.0
three_hundred_eighteen.appe... | def _get_all_gnupg_options() | Get all GnuPG options and flags.
This is hardcoded within a local scope to reduce the chance of a tampered
GnuPG binary reporting falsified option sets, i.e. because certain options
(namedly the ``--no-options`` option, which prevents the usage of gpg.conf
files) are necessary and statically specified ... | 3.883426 | 4.051044 | 0.958623 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.