function stringlengths 11 56k | repo_name stringlengths 5 60 | features list |
|---|---|---|
def __init__(self, key, child_proxy):
try:
self._key = int(key)
except ValueError:
self._key = key
self._child_proxy = child_proxy | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def __init__(self):
self._cache = {}
self._bucket_client = None
self._param_client = None
self._secret_client = None | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def get_file_content(self, filepath):
cache_key = ("FILE", filepath)
def getter():
with open(filepath, "r") as f:
return f.read()
return self._get_or_create_cached_value(cache_key, getter) | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def getter():
return self._secret_client.get(name) | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def get_bucket_file(self, key):
cache_key = ("BUCKET_FILE", key)
if not self._bucket_client:
self._bucket_client = get_bucket_client()
def getter():
return self._bucket_client.download_to_tmpfile(key)
return self._get_or_create_cached_value(cache_key, getter) | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def getter():
return self._param_client.get(key) | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def __init__(self, path=None, resolver=None):
self._path = path or ()
if not resolver:
resolver = Resolver()
self._resolver = resolver | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def _from_python(self, key, value):
new_path = self._path + (key,)
if isinstance(value, dict):
value = self.custom_classes.get(new_path, ConfigDict)(value, new_path)
elif isinstance(value, list):
value = self.custom_classes.get(new_path, ConfigList)(value, new_path)
... | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def __len__(self):
return len(self._collection) | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def __setitem__(self, key, value):
self._collection[key] = self._from_python(key, value) | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def __init__(self, config_l, path=None, resolver=None):
super().__init__(path=path, resolver=resolver)
self._collection = []
for key, value in enumerate(config_l):
self._collection.append(self._from_python(str(key), value)) | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def __iter__(self):
for element in self._collection:
yield self._to_python(element) | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def __init__(self, config_d, path=None, resolver=None):
super().__init__(path=path, resolver=resolver)
self._collection = {}
for key, value in config_d.items():
self._collection[key] = self._from_python(key, value) | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def get(self, key, default=None):
try:
value = self[key]
except KeyError:
value = self._to_python(default)
return value | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def keys(self):
return self._collection.keys() | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def items(self):
for key, value in self._collection.items():
yield key, self._to_python(value) | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def setdefault(self, key, default=None):
return self._collection.setdefault(key, self._from_python(key, default)) | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def popitem(self):
key, value = self._collection.popitem()
return key, self._to_python(value) | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def update(self, *args, **kwargs):
chain = []
for arg in args:
if isinstance(arg, dict):
iterator = arg.items()
else:
iterator = arg
chain = itertools.chain(chain, iterator)
if kwargs:
chain = itertools.chain(chain, ... | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def get_schema(self):
"""Returns the set YAML schema for the metric class.
Returns:
YAML schema of the metrics type.
"""
return self._schema | kubeflow/pipelines | [
3125,
1400,
3125,
892,
1526085107
] |
def __init__(self, schema_file: str):
self._schema = artifact_utils.read_schema_file(schema_file)
self._type_name, self._metric_fields = artifact_utils.parse_schema(
self._schema)
self._values = {} | kubeflow/pipelines | [
3125,
1400,
3125,
892,
1526085107
] |
def __getattr__(self, name: str) -> Any:
"""Custom __getattr__ to allow access to metrics schema fields."""
if name not in self._metric_fields:
raise AttributeError('No field: {} in metrics.'.format(name))
return self._values[name] | kubeflow/pipelines | [
3125,
1400,
3125,
892,
1526085107
] |
def __init__(self):
super().__init__('confidence_metrics.yaml')
self._initialized = True | kubeflow/pipelines | [
3125,
1400,
3125,
892,
1526085107
] |
def __init__(self):
super().__init__('confusion_matrix.yaml')
self._matrix = [[]]
self._categories = []
self._initialized = True | kubeflow/pipelines | [
3125,
1400,
3125,
892,
1526085107
] |
def log_row(self, row_category: str, row: List[int]):
"""Logs a confusion matrix row.
Args:
row_category: Category to which the row belongs.
row: List of integers specifying the values for the row.
Raises:
ValueError: If row_category is not in the list of categori... | kubeflow/pipelines | [
3125,
1400,
3125,
892,
1526085107
] |
def __init__(self,inp='INP.mcnp'):
""" Wrapped Cylinder MCNPX Model of RPM8
Keywords:
inp -- desired name of the input deck
"""
# Material dictionary for the moderator, light guide, and detector
self.material = {'Moderator':None,'Detector':None,'LightGuide':None}
... | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def __str__(self):
s = '\tMCNPX Model of Wrapped Cylinder\n'
s += '\t Cell Number Starts: {0:d}\n'.format(self.CellStartNum)
s += '\t Surface Number Starts: {0:d}\n'.format(self.SurfaceStartNum)
return s | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def setMaterial(self,massFraction,polymer):
"""
Sets the detector material
"""
M = Materials()
num = self.material['Detector']['mt']
if polymer == 'PS':
self.material['Detector']['matString'] = M.GetPSLiF(massFraction,num)
elif polymer == 'PEN':
... | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def calculateDetectorArea(self):
"""
Calculates the area used in a detector
"""
area = 0.0
r = self.geoParam['CylinderLightGuideRadius']
while(r + self.geoParam['DetectorThickness'] < self.geoParam['CylinderRadius']):
area -= math.pow(r,2)
r += sel... | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def runModel(self):
"""
Runs the Model by submission to Tourqe / Maui
"""
qsub= subprocess.check_output('which qsub',shell=True).strip()
cmd = '#!/bin/bash\n'
cmd += '#PBS -N {0}\n#PBS -V\n#PBS -q gen1\n#PBS -l nodes=1:ppn=1\n'
cmd += 'cd $PBS_O_WORKDIR\nmpirun m... | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def createInputDeck(self,cylinderPositions,inp=None,name=None):
""" createInputDeck
Creates an input deck of the given geometry
"""
self.inp = inp
self.name = name
if not inp:
self.inp = 'INP_Cylinder.mcnp'
if not name:
self.name = 'OUT_C... | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def getRunString(self):
runString ='c ------------------------------ Run Info ---------------------------------\n'
runString +='nps 1E6 \n'
runString +='IMP:N 1 {0:d}R 0 $ Particle Importances within cells \n'... | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def getMaterialString(self):
"""
Returns the MCNXP material string
"""
matString = 'm10 1001.70c -0.080538 $Lucite (PMMA / Plexiglass) rho = 1.19 g/cc\n'
matString += ' 6012.70c -0.599848 8016.70c -0.319614 \n'
matString +=... | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def RunCylinder(l,p,cylinderPositions):
"""
Runs an mcnpx model of the cylinder of loading l, polymer p, with
cylinder positions cylinderPositions.
Keywords:
l - loading of the films
p - polymer
cylinderPositions - the cylinder positons
"""
# Creating input and output de... | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def PositionOptimization(loading,polymers,positions):
"""
Runs a matrix of loading, polymers and positions
"""
for l in loading:
for p in polymers:
for pos in positions:
RunCylinder(l,p,pos) | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def createInputPlotDecks():
positions = list()
positions.append(((4.23,10.16),(4.23,-10.16)))
positions.append(((4.23,7.625),(4.23,0),(4.23,-7.625)))
#positions.append(((4.23,9.15),(4.23,3.05),(4.23,-3.05),(4.23,-9.15)))
for pos in positions:
m = CylinderRPM()
m.createSurfaceGeo()
... | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def extractRunInfo(filename):
"""
Extracts the loading and polymer from the file name
"""
tokens = filename.split('_')
loading = tokens[1].strip('LiF')
polymer = tokens[2].strip('.m')
return (float(loading)/100, polymer) | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def GetInteractionRate(f,tallyNum=54,src=2.3E3):
"""
Returns the interaction rate of the mctal file
"""
m = mctal.MCTAL(f)
t = m.tallies[tallyNum]
return (t.data[-1]*src,t.errors[-1]*t.data[-1]*src) | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def summerize():
files = glob.glob('OUTCylinder*.m')
s = 'Polymer, loading, mass Li, count rate, error, count rate per mass\n'
for f in files:
runParam = extractRunInfo(f)
massLi = computeMassLi(runParam[1],runParam[0])
countRate = GetInteractionRate(f)
s += '{}, {:5.2f} , ... | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def cleanup(path):
files = glob.glob(path+'/OUTCyl_*.m')
for f in files:
head,tail = os.path.split(f)
numCylinders = tail.count('-')+1
if numCylinders == 3:
newdir = 'ThreeCylPosOpt'
elif numCylinders == 4:
newdir = 'FourCylPosOpt'
elif numCylinder... | murffer/DetectorSim | [
7,
5,
7,
1,
1380841989
] |
def __init__(self, version=None):
"""
Initialize a new Postgres object
:param version: version to use. If it is not set, use the latest version in .pyembedpg directory. If not present
use the latest version remotely. Use 'local' to use the local postgres version installed... | Simulmedia/pyembedpg | [
31,
8,
31,
2,
1437597497
] |
def get_latest_remote_version(self):
"""
Return the latest version on the Postgres FTP server
:return: latest version installed locally on the Postgres FTP server
"""
response = requests.get(PyEmbedPg.DOWNLOAD_BASE_URL)
last_version_match = list(re.finditer('>v(?P<version... | Simulmedia/pyembedpg | [
31,
8,
31,
2,
1437597497
] |
def download_and_unpack(self):
# if the version we want to download already exists, do not do anything
if self.check_version_present():
logger.debug('Version {version} already present in cache'.format(version=self.version))
return
url = PyEmbedPg.DOWNLOAD_URL.format(vers... | Simulmedia/pyembedpg | [
31,
8,
31,
2,
1437597497
] |
def __init__(self, bin_dir, ports):
self._ports = ports
self._postgres_cmd = os.path.join(bin_dir, 'postgres')
# init db
init_db = os.path.join(bin_dir, 'initdb')
self._temp_dir = tempfile.mkdtemp()
command = init_db + ' -D ' + self._temp_dir + ' -U ' + DatabaseRunner.AD... | Simulmedia/pyembedpg | [
31,
8,
31,
2,
1437597497
] |
def __exit__(self, exc_type, exc_val, exc_tb):
self.shutdown() | Simulmedia/pyembedpg | [
31,
8,
31,
2,
1437597497
] |
def create_database(self, name, owner=None):
"""Create a new database
:param name: database name
:type name: basestring
:param owner: username of the owner or None if unspecified
:type owner: basestring
"""
with psycopg2.connect(database='postgres', user=DatabaseR... | Simulmedia/pyembedpg | [
31,
8,
31,
2,
1437597497
] |
def _is_multiclass(context):
"""Returns True iff we're given a multiclass context."""
if not isinstance(context, subsettable_context.SubsettableContext):
raise TypeError("context must be a SubsettableContext object")
raw_context = context.raw_context
return raw_context.num_classes is not None | google-research/tensorflow_constrained_optimization | [
282,
49,
282,
12,
1548359328
] |
def update_ops_fn(denominator_bound_variable, structure_memoizer,
value_memoizer):
"""Projects denominator_bound onto the feasible region."""
del value_memoizer
denominator_bound = tf.maximum(
structure_memoizer[defaults.DENOMINATOR_LOWER_BOUND_KEY],
tf.minimum(1.0, deno... | google-research/tensorflow_constrained_optimization | [
282,
49,
282,
12,
1548359328
] |
def _ratio(numerator_expression, denominator_expression):
"""Creates an `Expression` for a ratio.
The result of this function is an `Expression` representing:
numerator / denominator_bound
where denominator_bound satisfies the following:
denominator_lower_bound <= denominator_bound <= 1
The resulting `... | google-research/tensorflow_constrained_optimization | [
282,
49,
282,
12,
1548359328
] |
def negative_prediction_rate(context,
positive_class=None,
penalty_loss=defaults.DEFAULT_PENALTY_LOSS,
constraint_loss=defaults.DEFAULT_CONSTRAINT_LOSS):
"""Creates an `Expression` for a negative prediction rate.
A negative pred... | google-research/tensorflow_constrained_optimization | [
282,
49,
282,
12,
1548359328
] |
def accuracy_rate(context,
penalty_loss=defaults.DEFAULT_PENALTY_LOSS,
constraint_loss=defaults.DEFAULT_CONSTRAINT_LOSS):
"""Creates an `Expression` for an accuracy rate.
An accuracy rate is the number of examples within the given context on which
the model makes a correct pre... | google-research/tensorflow_constrained_optimization | [
282,
49,
282,
12,
1548359328
] |
def false_negative_rate(context,
positive_class=None,
penalty_loss=defaults.DEFAULT_PENALTY_LOSS,
constraint_loss=defaults.DEFAULT_CONSTRAINT_LOSS):
"""Creates an `Expression` for a false negative rate.
A false negative rate is the number of p... | google-research/tensorflow_constrained_optimization | [
282,
49,
282,
12,
1548359328
] |
def true_negative_rate(context,
positive_class=None,
penalty_loss=defaults.DEFAULT_PENALTY_LOSS,
constraint_loss=defaults.DEFAULT_CONSTRAINT_LOSS):
"""Creates an `Expression` for a true negative rate.
A true negative rate is the number of negativ... | google-research/tensorflow_constrained_optimization | [
282,
49,
282,
12,
1548359328
] |
def false_negative_proportion(context,
positive_class=None,
penalty_loss=defaults.DEFAULT_PENALTY_LOSS,
constraint_loss=defaults.DEFAULT_CONSTRAINT_LOSS):
"""Creates an `Expression` for a false negative proportion.
A false ne... | google-research/tensorflow_constrained_optimization | [
282,
49,
282,
12,
1548359328
] |
def true_negative_proportion(context,
positive_class=None,
penalty_loss=defaults.DEFAULT_PENALTY_LOSS,
constraint_loss=defaults.DEFAULT_CONSTRAINT_LOSS):
"""Creates an `Expression` for a true negative proportion.
A true negative... | google-research/tensorflow_constrained_optimization | [
282,
49,
282,
12,
1548359328
] |
def precision(context,
positive_class=None,
penalty_loss=defaults.DEFAULT_PENALTY_LOSS,
constraint_loss=defaults.DEFAULT_CONSTRAINT_LOSS):
"""Creates an `Expression`s for precision.
A precision is the number of positively-labeled examples within the given
context on whic... | google-research/tensorflow_constrained_optimization | [
282,
49,
282,
12,
1548359328
] |
def lhs_node(self, row):
pass | PeachstoneIO/peachbox | [
14,
4,
14,
7,
1427099581
] |
def import(row):
self.lhs_node(row.user_id)
self.rhs_node(row.review_id)
self.partition_key(row.time) | PeachstoneIO/peachbox | [
14,
4,
14,
7,
1427099581
] |
def __init__(self):
self.build_model() | PeachstoneIO/peachbox | [
14,
4,
14,
7,
1427099581
] |
def fill_review_id(self, row, field):
user_id = row['user_id']
product_id = row['product_id']
true_as_of_seconds = row['time']
return unicode(hash(user_id+product_id+str(true_as_of_seconds))) | PeachstoneIO/peachbox | [
14,
4,
14,
7,
1427099581
] |
def get_version():
version = ''
with open('grimreaper.py', 'r') as fd:
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
fd.read(), re.MULTILINE).group(1)
if not version:
raise RuntimeError("Cannot find version's information")
return version | matee911/GrimReapersPie | [
1,
1,
1,
3,
1442078546
] |
def __init__(self, store_name, context) -> None:
self.topic = f'{context.application_id}-{store_name}-changelog'
self.context = context
self.partition = context.task_id.partition
self.record_collector = context.state_record_collector | wintoncode/winton-kafka-streams | [
313,
56,
313,
13,
1499849928
] |
def test_sim_updates(self, disc_lr, gen_lr):
# player order does not matter.
# the number of updates does not matter for simultaneous updates.
learning_rates = gan.GANTuple(disc=disc_lr, gen=gen_lr)
drift_coeffs = drift_utils.get_dd_coeffs(
None, True, learning_rates, num_updates=None)
self... | deepmind/dd_two_player_games | [
4,
2,
4,
1,
1633120481
] |
def test_alt_updates(self, disc_lr, gen_lr):
learning_rates = gan.GANTuple(disc=disc_lr, gen=gen_lr)
num_updates = gan.GANTuple(disc=1, gen=1)
drift_coeffs = drift_utils.get_dd_coeffs(
drift_utils.PlayerOrder.disc_first, False, learning_rates,
num_updates=num_updates)
self.assertEqual(d... | deepmind/dd_two_player_games | [
4,
2,
4,
1,
1633120481
] |
def test_alt_updates_change_player_order(self, disc_lr, gen_lr):
learning_rates = gan.GANTuple(disc=disc_lr, gen=gen_lr)
num_updates = gan.GANTuple(disc=1, gen=1)
drift_coeffs = drift_utils.get_dd_coeffs(
drift_utils.PlayerOrder.gen_first, False, learning_rates,
num_updates=num_updates)
... | deepmind/dd_two_player_games | [
4,
2,
4,
1,
1633120481
] |
def managed_task(task_function):
"""Decorator to manage task methods.
This records the status of the task in an entity and raises the
deferred.PermanentTaskFailure exception to prevent tasks from repeating upon
failure. In such cases, the exception message is recorded to the entity.
Args:
task_function:... | google/loaner | [
167,
61,
167,
23,
1522269186
] |
def bootstrap_datastore_yaml(wipe=True, **kwargs):
"""Bootstraps arbitrary datastore entities from supplied YAML input.
Args:
wipe: bool, whether to wipe all existing datastore models for any model
contained in the YAML.
**kwargs: keyword args including a user_email with which to run the
da... | google/loaner | [
167,
61,
167,
23,
1522269186
] |
def bootstrap_chrome_ous(**kwargs):
"""Bootstraps Chrome device OUs.
Args:
**kwargs: keyword args including a user_email with which to run the
Directory API client methods (required for BigQuery streaming).
"""
logging.info('Requesting delegated admin for bootstrap')
client = directory.DirectoryA... | google/loaner | [
167,
61,
167,
23,
1522269186
] |
def bootstrap_bq_history(**kwargs):
"""Bootstraps BigQuery history tables for archival purposes.
Args:
**kwargs: keyword args including a user_email with which to run the
Directory API client methods (required for BigQuery streaming).
"""
del kwargs # Unused, but comes by default.
client = bigqu... | google/loaner | [
167,
61,
167,
23,
1522269186
] |
def bootstrap_load_config_yaml(**kwargs):
"""Loads config_defaults.yaml into datastore.
Args:
**kwargs: Unused, but required for bootstrap tasks.
"""
del kwargs # Unused, but comes by default.
config_defaults = utils.load_config_from_yaml()
for name, value in config_defaults.iteritems():
if name =... | google/loaner | [
167,
61,
167,
23,
1522269186
] |
def _run_function_as_task(all_functions_list, function_name, kwargs=None):
"""Runs a specific function and its kwargs as an AppEngine task.
Args:
all_functions_list: string list, A list with all function names that are
registered as bootstrap functions on the Loaner app.
function_name: string, A sp... | google/loaner | [
167,
61,
167,
23,
1522269186
] |
def _is_new_deployment():
"""Checks whether this is a new deployment.
A '0.0' version number and a missing bootstrap_datastore_yaml task
status indicates that this is a new deployment. The latter check
is to support backward-compatibility with early alpha versions that did not
have a version number.
... | google/loaner | [
167,
61,
167,
23,
1522269186
] |
def is_update():
"""Checks whether the application is in a state requiring an update.
Returns:
True if an update is available and this is not a new installation.
"""
if _is_new_deployment():
return False
return version.LooseVersion(constants.APP_VERSION) > version.LooseVersion(
config_model.Co... | google/loaner | [
167,
61,
167,
23,
1522269186
] |
def is_bootstrap_started():
"""Checks to see if bootstrap has started.
Returns:
True if the bootstrap has started, else False.
"""
if (config_model.Config.get('bootstrap_started') and
config_model.Config.get('bootstrap_completed')):
# If bootstrap was completed indicate that it is no longer in pr... | google/loaner | [
167,
61,
167,
23,
1522269186
] |
def test_equality():
assert cirq_google.PhysicalZTag() == cirq_google.PhysicalZTag()
assert hash(cirq_google.PhysicalZTag()) == hash(cirq_google.PhysicalZTag()) | quantumlib/Cirq | [
3678,
836,
3678,
314,
1513294909
] |
def __init__(self):
"""Initialize class."""
self.verbose = False
self.home = os.getcwd() | major/monitorstack | [
1,
1,
1,
1,
1487693141
] |
def vlog(self, msg, *args):
"""Log a message to stderr only if verbose is enabled."""
if self.verbose:
self.log(msg, *args) | major/monitorstack | [
1,
1,
1,
1,
1487693141
] |
def cmd_folder(self):
"""Get the path to the plugin directory."""
return os.path.abspath(
os.path.join(
os.path.dirname(__file__),
'plugins'
)
) | major/monitorstack | [
1,
1,
1,
1,
1487693141
] |
def get_command(self, ctx, name):
"""Load a command and run it."""
for _, pkg_name, _ in pkgutil.iter_modules([self.cmd_folder]):
if pkg_name == name:
mod = importlib.import_module(
'monitorstack.plugins.{}'.format(name)
)
r... | major/monitorstack | [
1,
1,
1,
1,
1487693141
] |
def cli(*args, **kwargs):
"""A complex command line interface."""
try:
args[0].verbose = kwargs.get('verbose', False)
except IndexError: # pragma: no cover
pass | major/monitorstack | [
1,
1,
1,
1,
1487693141
] |
def process_result(results, output_format, **kwargs):
"""Render the output into the proper format."""
module_name = 'monitorstack.common.formatters'
method_name = 'write_{}'.format(output_format.replace('-', '_'))
output_formatter = getattr(
importlib.import_module(module_name),
method_n... | major/monitorstack | [
1,
1,
1,
1,
1487693141
] |
def _basic_alert():
return Alert('test_rule', {'abc': 123}, {'aws-firehose:alerts', 'aws-sns:test-output'}) | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def _customized_alert():
return Alert(
'test_rule',
{'abc': 123},
{'aws-firehose:alerts', 'aws-sns:test-output', 'aws-s3:other-output'},
alert_id='abc-123',
attempts=1,
cluster='',
context={'rule': 'context'},
create... | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_init_invalid_kwargs(self):
"""Alert Class - Init With Invalid Kwargs"""
assert_raises(AlertCreationError, Alert, '', {}, set(), cluster='test', invalid='nonsense') | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_repr(self):
"""Alert Class - Complete Alert Representation"""
assert_is_instance(repr(self._basic_alert()), str)
assert_is_instance(repr(self._customized_alert()), str) | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_dynamo_key(self):
"""Alert Class - Dynamo Key"""
alert = self._customized_alert()
assert_equal({'RuleName': 'test_rule', 'AlertID': 'abc-123'}, alert.dynamo_key) | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_remaining_outputs_merge_enabled(self):
"""Alert Class - Remaining Outputs - With Merge Config"""
# Only the required firehose output shows as remaining
assert_equal({'aws-firehose:alerts'}, self._customized_alert().remaining_outputs) | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_create_from_dynamo_record(self):
"""Alert Class - Create Alert from Dynamo Record"""
alert = self._customized_alert()
# Converting to a Dynamo record and back again should result in the exact same alert
record = alert.dynamo_record()
new_alert = Alert.create_from_dynamo_... | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_output_dict(self):
"""Alert Class - Output Dict"""
alert = self._basic_alert()
result = alert.output_dict()
# Ensure result is JSON-serializable (no sets)
assert_is_instance(json.dumps(result), str)
# Ensure result is Athena compatible (no None values)
as... | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_can_merge_too_far_apart(self):
"""Alert Class - Can Merge - False if Outside Merge Window"""
alert1 = Alert(
'', {'key': True}, set(),
created=datetime(year=2000, month=1, day=1, minute=0),
merge_by_keys=['key'],
merge_window=timedelta(minutes=10)... | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_can_merge_key_not_common(self):
"""Alert Class - Can Merge - False if Merge Key Not Present in Both Records"""
alert1 = Alert(
'', {'key': True}, set(),
merge_by_keys=['key'],
merge_window=timedelta(minutes=10)
)
alert2 = Alert(
''... | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_can_merge_merge_keys_absent(self):
"""Alert Class - Can Merge - True if Merge Keys Do Not Exist in Either Record"""
alert1 = Alert('', {}, set(), merge_by_keys=['key'], merge_window=timedelta(minutes=10))
alert2 = Alert('', {}, set(), merge_by_keys=['key'], merge_window=timedelta(minute... | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_compute_common_empty_record(self):
"""Alert Class - Compute Common - Empty Record List"""
assert_equal({}, Alert._compute_common([])) | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_compute_common_top_level(self):
"""Alert Class - Compute Common - No Nested Dictionaries"""
record1 = {'a': 1, 'b': 2, 'c': 3}
record2 = {'b': 2, 'c': 3, 'd': 4}
record3 = {'c': 3, 'd': 4, 'e': 5}
assert_equal({'c': 3}, Alert._compute_common([record1, record2, record3])) | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_compute_common_partial_nested(self):
"""Alert Class - Compute Common - Some Common Features in Nested Dictionary"""
# This is the example given in the docstring
record1 = {'abc': 123, 'nested': {'A': 1, 'B': 2}}
record2 = {'abc': 123, 'def': 456, 'nested': {'A': 1}}
asse... | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_compute_common_many_nested(self):
"""Alert Class - Compute Common - Multiple Levels of Nesting"""
record1 = {
'a': {
'b': {
'c': 3,
'd': 4
},
'e': {
'h': {
... | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_compute_diff_no_common(self):
"""Alert Class - Compute Diff - No Common Set"""
record = {'a': 1, 'b': 2, 'c': {'d': {'e': 3}}}
assert_equal(record, Alert._compute_diff({}, record)) | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_compute_diff_top_level(self):
"""Alert Class - Compute Diff - Top Level Keys"""
common = {'c': 3}
record = {'a': 1, 'b': 2, 'c': 3}
assert_equal({'a': 1, 'b': 2}, Alert._compute_diff(common, record)) | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_compute_diff_nested(self):
"""Alert Class - Compute Diff - Difference in Nested Dictionary"""
# This is the example given in the docstring
common = {'abc': 123, 'nested': {'A': 1}}
record = {'abc': 123, 'nested': {'A': 1, 'B': 2}}
assert_equal({'nested': {'B': 2}}, Alert... | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
def test_merge(self):
"""Alert Class - Merge - Create Merged Alert"""
# Example based on a CarbonBlack log
record1 = {
'alliance_data_virustotal': [],
'alliance_link_virustotal': '',
'alliance_score_virustotal': 0,
'cmdline': 'whoami',
... | airbnb/streamalert | [
2767,
342,
2767,
92,
1485047456
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.