code
stringlengths 26
870k
| docstring
stringlengths 1
65.6k
| func_name
stringlengths 1
194
| language
stringclasses 1
value | repo
stringlengths 8
68
| path
stringlengths 5
194
| url
stringlengths 46
254
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
def setUp(self):
""" Cleanup before each test. """
_cleanup() | Cleanup before each test. | setUp | python | spotify/luigi | test/contrib/esindex_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/esindex_test.py | Apache-2.0 |
def tearDown(self):
""" Remove residues after each test. """
_cleanup() | Remove residues after each test. | tearDown | python | spotify/luigi | test/contrib/esindex_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/esindex_test.py | Apache-2.0 |
def test_copy_to_index(self):
""" Test a single document upload. """
task = IndexingTask1()
self.assertFalse(self.es.indices.exists(task.index))
self.assertFalse(task.complete())
luigi.build([task], local_scheduler=True)
self.assertTrue(self.es.indices.exists(task.index))
self.assertTrue(task.complete())
self.assertEqual(1, self.es.count(index=task.index).get('count'))
self.assertEqual({u'date': u'today', u'name': u'sample'},
self.es.get_source(index=task.index,
doc_type=task.doc_type, id=123)) | Test a single document upload. | test_copy_to_index | python | spotify/luigi | test/contrib/esindex_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/esindex_test.py | Apache-2.0 |
def test_copy_to_index_incrementally(self):
""" Test two tasks that upload docs into the same index. """
task1 = IndexingTask1()
task2 = IndexingTask2()
self.assertFalse(self.es.indices.exists(task1.index))
self.assertFalse(self.es.indices.exists(task2.index))
self.assertFalse(task1.complete())
self.assertFalse(task2.complete())
luigi.build([task1, task2], local_scheduler=True)
self.assertTrue(self.es.indices.exists(task1.index))
self.assertTrue(self.es.indices.exists(task2.index))
self.assertTrue(task1.complete())
self.assertTrue(task2.complete())
self.assertEqual(2, self.es.count(index=task1.index).get('count'))
self.assertEqual(2, self.es.count(index=task2.index).get('count'))
self.assertEqual({u'date': u'today', u'name': u'sample'},
self.es.get_source(index=task1.index,
doc_type=task1.doc_type, id=123))
self.assertEqual({u'date': u'today', u'name': u'another'},
self.es.get_source(index=task2.index,
doc_type=task2.doc_type, id=234)) | Test two tasks that upload docs into the same index. | test_copy_to_index_incrementally | python | spotify/luigi | test/contrib/esindex_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/esindex_test.py | Apache-2.0 |
def test_copy_to_index_purge_existing(self):
""" Test purge_existing_index purges index. """
task1 = IndexingTask1()
task2 = IndexingTask2()
task3 = IndexingTask3()
luigi.build([task1, task2], local_scheduler=True)
luigi.build([task3], local_scheduler=True)
self.assertTrue(self.es.indices.exists(task3.index))
self.assertTrue(task3.complete())
self.assertEqual(1, self.es.count(index=task3.index).get('count'))
self.assertEqual({u'date': u'today', u'name': u'yet another'},
self.es.get_source(index=task3.index,
doc_type=task3.doc_type, id=234)) | Test purge_existing_index purges index. | test_copy_to_index_purge_existing | python | spotify/luigi | test/contrib/esindex_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/esindex_test.py | Apache-2.0 |
def setUp(self):
""" Cleanup before each test. """
_cleanup() | Cleanup before each test. | setUp | python | spotify/luigi | test/contrib/esindex_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/esindex_test.py | Apache-2.0 |
def tearDown(self):
""" Remove residues after each test. """
_cleanup() | Remove residues after each test. | tearDown | python | spotify/luigi | test/contrib/esindex_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/esindex_test.py | Apache-2.0 |
def docs(self):
""" Return a list with a single doc. """
return [{'_id': 234, '_index': self.index, '_type': self.doc_type,
'name': 'another', 'date': 'today'}] | Return a list with a single doc. | docs | python | spotify/luigi | test/contrib/esindex_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/esindex_test.py | Apache-2.0 |
def setUp(self):
""" Cleanup before each test. """
_cleanup() | Cleanup before each test. | setUp | python | spotify/luigi | test/contrib/esindex_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/esindex_test.py | Apache-2.0 |
def tearDown(self):
""" Remove residues after each test. """
_cleanup() | Remove residues after each test. | tearDown | python | spotify/luigi | test/contrib/esindex_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/esindex_test.py | Apache-2.0 |
def bucket_url(suffix):
"""
Actually it's bucket + test folder name
"""
return 'gs://{}/{}/{}'.format(BUCKET_NAME, TEST_FOLDER, suffix) | Actually it's bucket + test folder name | bucket_url | python | spotify/luigi | test/contrib/bigquery_gcloud_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/bigquery_gcloud_test.py | Apache-2.0 |
def test_init_without_init_or_config(self, mock):
"""If no config or arn provided, boto3 client
should be called with default parameters.
Delegating ENV or Task Role credential handling
to boto3 itself.
"""
S3Client().s3
mock.assert_called_with('s3', aws_access_key_id=None,
aws_secret_access_key=None, aws_session_token=None) | If no config or arn provided, boto3 client
should be called with default parameters.
Delegating ENV or Task Role credential handling
to boto3 itself. | test_init_without_init_or_config | python | spotify/luigi | test/contrib/s3_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/s3_test.py | Apache-2.0 |
def test_put_multipart_multiple_parts_non_exact_fit(self):
"""
Test a multipart put with two parts, where the parts are not exactly the split size.
"""
# 5MB is minimum part size
part_size = 8388608
file_size = (part_size * 2) - 1000
return self._run_multipart_test(part_size, file_size) | Test a multipart put with two parts, where the parts are not exactly the split size. | test_put_multipart_multiple_parts_non_exact_fit | python | spotify/luigi | test/contrib/s3_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/s3_test.py | Apache-2.0 |
def test_put_multipart_multiple_parts_exact_fit(self):
"""
Test a multipart put with multiple parts, where the parts are exactly the split size.
"""
# 5MB is minimum part size
part_size = 8388608
file_size = part_size * 2
return self._run_multipart_test(part_size, file_size) | Test a multipart put with multiple parts, where the parts are exactly the split size. | test_put_multipart_multiple_parts_exact_fit | python | spotify/luigi | test/contrib/s3_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/s3_test.py | Apache-2.0 |
def test_put_multipart_empty_file(self):
"""
Test a multipart put with an empty file.
"""
# 5MB is minimum part size
part_size = 8388608
file_size = 0
return self._run_multipart_test(part_size, file_size) | Test a multipart put with an empty file. | test_put_multipart_empty_file | python | spotify/luigi | test/contrib/s3_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/s3_test.py | Apache-2.0 |
def test_put_multipart_less_than_split_size(self):
"""
Test a multipart put with a file smaller than split size; should revert to regular put.
"""
# 5MB is minimum part size
part_size = 8388608
file_size = 5000
return self._run_multipart_test(part_size, file_size) | Test a multipart put with a file smaller than split size; should revert to regular put. | test_put_multipart_less_than_split_size | python | spotify/luigi | test/contrib/s3_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/s3_test.py | Apache-2.0 |
def test_copy_multiple_parts_non_exact_fit(self):
"""
Test a multipart put with two parts, where the parts are not exactly the split size.
"""
# First, put a file into S3
self._run_copy_test(self.test_put_multipart_multiple_parts_non_exact_fit) | Test a multipart put with two parts, where the parts are not exactly the split size. | test_copy_multiple_parts_non_exact_fit | python | spotify/luigi | test/contrib/s3_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/s3_test.py | Apache-2.0 |
def test_copy_multiple_parts_exact_fit(self):
"""
Test a copy multiple parts, where the parts are exactly the split size.
"""
self._run_copy_test(self.test_put_multipart_multiple_parts_exact_fit) | Test a copy multiple parts, where the parts are exactly the split size. | test_copy_multiple_parts_exact_fit | python | spotify/luigi | test/contrib/s3_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/s3_test.py | Apache-2.0 |
def test_copy_less_than_split_size(self):
"""
Test a copy with a file smaller than split size; should revert to regular put.
"""
self._run_copy_test(self.test_put_multipart_less_than_split_size) | Test a copy with a file smaller than split size; should revert to regular put. | test_copy_less_than_split_size | python | spotify/luigi | test/contrib/s3_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/s3_test.py | Apache-2.0 |
def test_copy_empty_file(self):
"""
Test a copy with an empty file.
"""
self._run_copy_test(self.test_put_multipart_empty_file) | Test a copy with an empty file. | test_copy_empty_file | python | spotify/luigi | test/contrib/s3_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/s3_test.py | Apache-2.0 |
def test_copy_empty_dir(self):
"""
Test copying an empty dir
"""
create_bucket()
s3_dir = 's3://mybucket/copydir/'
s3_client = S3Client(AWS_ACCESS_KEY, AWS_SECRET_KEY)
s3_client.mkdir(s3_dir)
self.assertTrue(s3_client.exists(s3_dir))
s3_dest = 's3://mybucket/copydir_new/'
response = s3_client.copy(s3_dir, s3_dest)
self._run_copy_response_test(response, expected_num=0, expected_size=0) | Test copying an empty dir | test_copy_empty_dir | python | spotify/luigi | test/contrib/s3_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/s3_test.py | Apache-2.0 |
def test_copy_dir(self):
"""
Test copying 20 files from one folder to another
"""
create_bucket()
n = 20
copy_part_size = (1024 ** 2) * 5
# Note we can't test the multipart copy due to moto issue #526
# so here I have to keep the file size smaller than the copy_part_size
file_size = 5000
s3_dir = 's3://mybucket/copydir/'
file_contents = b"a" * file_size
tmp_file = tempfile.NamedTemporaryFile(mode='wb', delete=True)
tmp_file_path = tmp_file.name
tmp_file.write(file_contents)
tmp_file.flush()
s3_client = S3Client(AWS_ACCESS_KEY, AWS_SECRET_KEY)
for i in range(n):
file_path = s3_dir + str(i)
s3_client.put_multipart(tmp_file_path, file_path)
self.assertTrue(s3_client.exists(file_path))
s3_dest = 's3://mybucket/copydir_new/'
response = s3_client.copy(s3_dir, s3_dest, threads=10, part_size=copy_part_size)
self._run_copy_response_test(response, expected_num=n, expected_size=(n * file_size))
for i in range(n):
original_size = s3_client.get_key(s3_dir + str(i)).size
copy_size = s3_client.get_key(s3_dest + str(i)).size
self.assertEqual(original_size, copy_size) | Test copying 20 files from one folder to another | test_copy_dir | python | spotify/luigi | test/contrib/s3_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/s3_test.py | Apache-2.0 |
def test_invalid_target(self):
'''Verify invalid types raises NoOpenerError
'''
self.assertRaises(NoOpenerError, OpenerTarget, 'foo://bar.txt') | Verify invalid types raises NoOpenerError | test_invalid_target | python | spotify/luigi | test/contrib/opener_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/opener_test.py | Apache-2.0 |
def test_mock_target(self):
'''Verify mock target url
'''
target = OpenerTarget('mock://foo/bar.txt')
self.assertEqual(type(target), MockTarget)
# Write to the target
target.open('w').close()
self.assertTrue(MockTarget.fs.exists('foo/bar.txt')) | Verify mock target url | test_mock_target | python | spotify/luigi | test/contrib/opener_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/opener_test.py | Apache-2.0 |
def test_mock_target_root(self):
'''Verify mock target url
'''
target = OpenerTarget('mock:///foo/bar.txt')
self.assertEqual(type(target), MockTarget)
# Write to the target
target.open('w').close()
self.assertTrue(MockTarget.fs.exists('/foo/bar.txt')) | Verify mock target url | test_mock_target_root | python | spotify/luigi | test/contrib/opener_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/opener_test.py | Apache-2.0 |
def test_default_target(self):
'''Verify default local target url
'''
target = OpenerTarget(self.local_file)
self.assertEqual(type(target), LocalTarget)
# Write to the target
target.open('w').close()
self.assertTrue(LocalTarget.fs.exists(self.local_file)) | Verify default local target url | test_default_target | python | spotify/luigi | test/contrib/opener_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/opener_test.py | Apache-2.0 |
def test_local_target(self):
'''Verify basic local target url
'''
local_file = "file://{}".format(self.local_file)
target = OpenerTarget(local_file)
self.assertEqual(type(target), LocalTarget)
# Write to the target
target.open('w').close()
self.assertTrue(LocalTarget.fs.exists(self.local_file)) | Verify basic local target url | test_local_target | python | spotify/luigi | test/contrib/opener_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/opener_test.py | Apache-2.0 |
def test_local_tmp_target(self, lt_del_patch, lt_init_patch):
'''Verify local target url with query string
'''
lt_init_patch.return_value = None
lt_del_patch.return_value = None
local_file = "file://{}?is_tmp".format(self.local_file)
OpenerTarget(local_file)
lt_init_patch.assert_called_with(self.local_file, is_tmp=True) | Verify local target url with query string | test_local_tmp_target | python | spotify/luigi | test/contrib/opener_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/opener_test.py | Apache-2.0 |
def test_s3_parse(self, s3_init_patch):
'''Verify basic s3 target url
'''
s3_init_patch.return_value = None
local_file = "s3://zefr/foo/bar.txt"
OpenerTarget(local_file)
s3_init_patch.assert_called_with("s3://zefr/foo/bar.txt") | Verify basic s3 target url | test_s3_parse | python | spotify/luigi | test/contrib/opener_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/opener_test.py | Apache-2.0 |
def test_s3_parse_param(self, s3_init_patch):
'''Verify s3 target url with params
'''
s3_init_patch.return_value = None
local_file = "s3://zefr/foo/bar.txt?foo=hello&bar=true"
OpenerTarget(local_file)
s3_init_patch.assert_called_with("s3://zefr/foo/bar.txt",
foo='hello',
bar='true') | Verify s3 target url with params | test_s3_parse_param | python | spotify/luigi | test/contrib/opener_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/opener_test.py | Apache-2.0 |
def test_binary_support(self):
"""
Make sure keyword arguments are preserved through the OpenerTarget
"""
# Verify we can't normally write binary data
fp = OpenerTarget("mock://file.txt").open('w')
self.assertRaises(TypeError, fp.write, b'\x07\x08\x07')
# Verify the format is passed to the target and write binary data
fp = OpenerTarget("mock://file.txt",
format=luigi.format.MixedUnicodeBytes).open('w')
fp.write(b'\x07\x08\x07')
fp.close() | Make sure keyword arguments are preserved through the OpenerTarget | test_binary_support | python | spotify/luigi | test/contrib/opener_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/opener_test.py | Apache-2.0 |
def assertRegexpMatches(self, text, expected_regexp, msg=None):
"""Python 2.7 backport."""
if isinstance(expected_regexp, str):
expected_regexp = re.compile(expected_regexp)
if not expected_regexp.search(text):
msg = msg or "Regexp didn't match"
msg = '%s: %r not found in %r' % (msg, expected_regexp.pattern, text)
raise self.failureException(msg) | Python 2.7 backport. | assertRegexpMatches | python | spotify/luigi | test/contrib/hdfs_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/hdfs_test.py | Apache-2.0 |
def test_create_table(self):
"""
Test that this method creates table that we require
:return:
"""
class TestSQLData(sqla.CopyToTable):
connection_string = self.connection_string
connect_args = self.connect_args
table = "test_table"
columns = [
(["id", sqlalchemy.Integer], dict(primary_key=True)),
(["name", sqlalchemy.String(64)], {}),
(["value", sqlalchemy.String(64)], {})
]
chunk_size = 1
def output(self):
pass
sql_copy = TestSQLData()
eng = sqlalchemy.create_engine(TestSQLData.connection_string)
self.assertFalse(eng.dialect.has_table(eng.connect(), TestSQLData.table))
sql_copy.create_table(eng)
self.assertTrue(eng.dialect.has_table(eng.connect(), TestSQLData.table))
# repeat and ensure it just binds to existing table
sql_copy.create_table(eng) | Test that this method creates table that we require
:return: | test_create_table | python | spotify/luigi | test/contrib/sqla_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/sqla_test.py | Apache-2.0 |
def test_create_table_raises_no_columns(self):
"""
Check that the test fails when the columns are not set
:return:
"""
class TestSQLData(sqla.CopyToTable):
connection_string = self.connection_string
table = "test_table"
columns = []
chunk_size = 1
def output(self):
pass
sql_copy = TestSQLData()
eng = sqlalchemy.create_engine(TestSQLData.connection_string)
self.assertRaises(NotImplementedError, sql_copy.create_table, eng) | Check that the test fails when the columns are not set
:return: | test_create_table_raises_no_columns | python | spotify/luigi | test/contrib/sqla_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/sqla_test.py | Apache-2.0 |
def test_run(self):
"""
Checking that the runs go as expected. Rerunning the same shouldn't end up
inserting more rows into the db.
:return:
"""
task, task0 = self.SQLATask(), BaseTask()
self.engine = sqlalchemy.create_engine(task.connection_string)
luigi.build([task0, task], local_scheduler=True)
self._check_entries(self.engine)
# rerun and the num entries should be the same
luigi.build([task0, task], local_scheduler=True, workers=self.NUM_WORKERS)
self._check_entries(self.engine) | Checking that the runs go as expected. Rerunning the same shouldn't end up
inserting more rows into the db.
:return: | test_run | python | spotify/luigi | test/contrib/sqla_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/sqla_test.py | Apache-2.0 |
def test_run_with_chunk_size(self):
"""
The chunk_size can be specified in order to control the batch size for inserts.
:return:
"""
task, task0 = self.SQLATask(), BaseTask()
self.engine = sqlalchemy.create_engine(task.connection_string)
task.chunk_size = 2 # change chunk size and check it runs ok
luigi.build([task, task0], local_scheduler=True, workers=self.NUM_WORKERS)
self._check_entries(self.engine) | The chunk_size can be specified in order to control the batch size for inserts.
:return: | test_run_with_chunk_size | python | spotify/luigi | test/contrib/sqla_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/sqla_test.py | Apache-2.0 |
def test_reflect(self):
"""
If the table is setup already, then one can set reflect to True, and
completely skip the columns part. It is not even required at that point.
:return:
"""
SQLATask = self.SQLATask
class AnotherSQLATask(sqla.CopyToTable):
connection_string = self.connection_string
table = "item_property"
reflect = True
chunk_size = 1
def requires(self):
return SQLATask()
def copy(self, conn, ins_rows, table_bound):
ins = table_bound.update().\
where(table_bound.c.property == sqlalchemy.bindparam("_property")).\
values({table_bound.c.item: sqlalchemy.bindparam("_item")})
conn.execute(ins, ins_rows)
def rows(self):
for line in BaseTask.TASK_LIST:
yield line.strip("\n").split("\t")
task0, task1, task2 = AnotherSQLATask(), self.SQLATask(), BaseTask()
luigi.build([task0, task1, task2], local_scheduler=True, workers=self.NUM_WORKERS)
self._check_entries(self.engine) | If the table is setup already, then one can set reflect to True, and
completely skip the columns part. It is not even required at that point.
:return: | test_reflect | python | spotify/luigi | test/contrib/sqla_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/sqla_test.py | Apache-2.0 |
def test_create_marker_table(self):
"""
Is the marker table created as expected for the SQLAlchemyTarget
:return:
"""
target = sqla.SQLAlchemyTarget(self.connection_string, "test_table", "12312123")
target.create_marker_table()
self.assertTrue(target.engine.dialect.has_table(target.engine.connect(), target.marker_table)) | Is the marker table created as expected for the SQLAlchemyTarget
:return: | test_create_marker_table | python | spotify/luigi | test/contrib/sqla_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/sqla_test.py | Apache-2.0 |
def test_touch(self):
"""
Touch takes care of creating a checkpoint for task completion
:return:
"""
target = sqla.SQLAlchemyTarget(self.connection_string, "test_table", "12312123")
target.create_marker_table()
self.assertFalse(target.exists())
target.touch()
self.assertTrue(target.exists()) | Touch takes care of creating a checkpoint for task completion
:return: | test_touch | python | spotify/luigi | test/contrib/sqla_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/sqla_test.py | Apache-2.0 |
def test_row_overload(self):
"""Overload the rows method and we should be able to insert data into database"""
class SQLARowOverloadTest(sqla.CopyToTable):
columns = [
(["item", sqlalchemy.String(64)], {}),
(["property", sqlalchemy.String(64)], {})
]
connection_string = self.connection_string
table = "item_property"
chunk_size = 1
def rows(self):
tasks = [("item0", "property0"), ("item1", "property1"), ("item2", "property2"), ("item3", "property3"),
("item4", "property4"), ("item5", "property5"), ("item6", "property6"), ("item7", "property7"),
("item8", "property8"), ("item9", "property9")]
for row in tasks:
yield row
task = SQLARowOverloadTest()
luigi.build([task], local_scheduler=True, workers=self.NUM_WORKERS)
self._check_entries(self.engine) | Overload the rows method and we should be able to insert data into database | test_row_overload | python | spotify/luigi | test/contrib/sqla_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/sqla_test.py | Apache-2.0 |
def test_column_row_separator(self):
"""
Test alternate column row separator works
:return:
"""
class ModBaseTask(luigi.Task):
def output(self):
return MockTarget("ModBaseTask", mirror_on_stderr=True)
def run(self):
out = self.output().open("w")
tasks = ["item%d,property%d\n" % (i, i) for i in range(10)]
for task in tasks:
out.write(task)
out.close()
class ModSQLATask(sqla.CopyToTable):
columns = [
(["item", sqlalchemy.String(64)], {}),
(["property", sqlalchemy.String(64)], {})
]
connection_string = self.connection_string
table = "item_property"
column_separator = ","
chunk_size = 1
def requires(self):
return ModBaseTask()
task1, task2 = ModBaseTask(), ModSQLATask()
luigi.build([task1, task2], local_scheduler=True, workers=self.NUM_WORKERS)
self._check_entries(self.engine) | Test alternate column row separator works
:return: | test_column_row_separator | python | spotify/luigi | test/contrib/sqla_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/sqla_test.py | Apache-2.0 |
def test_update_rows_test(self):
"""
Overload the copy() method and implement an update action.
:return:
"""
class ModBaseTask(luigi.Task):
def output(self):
return MockTarget("BaseTask", mirror_on_stderr=True)
def run(self):
out = self.output().open("w")
for task in self.TASK_LIST:
out.write("dummy_" + task)
out.close()
class ModSQLATask(sqla.CopyToTable):
connection_string = self.connection_string
table = "item_property"
columns = [
(["item", sqlalchemy.String(64)], {}),
(["property", sqlalchemy.String(64)], {})
]
chunk_size = 1
def requires(self):
return ModBaseTask()
class UpdateSQLATask(sqla.CopyToTable):
connection_string = self.connection_string
table = "item_property"
reflect = True
chunk_size = 1
def requires(self):
return ModSQLATask()
def copy(self, conn, ins_rows, table_bound):
ins = table_bound.update().\
where(table_bound.c.property == sqlalchemy.bindparam("_property")).\
values({table_bound.c.item: sqlalchemy.bindparam("_item")})
conn.execute(ins, ins_rows)
def rows(self):
for task in self.TASK_LIST:
yield task.strip("\n").split("\t")
# Running only task1, and task2 should fail
task1, task2, task3 = ModBaseTask(), ModSQLATask(), UpdateSQLATask()
luigi.build([task1, task2, task3], local_scheduler=True, workers=self.NUM_WORKERS)
self._check_entries(self.engine) | Overload the copy() method and implement an update action.
:return: | test_update_rows_test | python | spotify/luigi | test/contrib/sqla_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/sqla_test.py | Apache-2.0 |
def test_multiple_tasks(self):
"""
Test a case where there are multiple tasks
:return:
"""
class SmallSQLATask(sqla.CopyToTable):
item = luigi.Parameter()
property = luigi.Parameter()
columns = [
(["item", sqlalchemy.String(64)], {}),
(["property", sqlalchemy.String(64)], {})
]
connection_string = self.connection_string
table = "item_property"
chunk_size = 1
def rows(self):
yield (self.item, self.property)
class ManyBaseTask(luigi.Task):
def requires(self):
for t in BaseTask.TASK_LIST:
item, property = t.strip().split("\t")
yield SmallSQLATask(item=item, property=property)
task2 = ManyBaseTask()
luigi.build([task2], local_scheduler=True, workers=self.NUM_WORKERS)
self._check_entries(self.engine) | Test a case where there are multiple tasks
:return: | test_multiple_tasks | python | spotify/luigi | test/contrib/sqla_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/sqla_test.py | Apache-2.0 |
def test_multiple_engines(self):
"""
Test case where different tasks require different SQL engines.
"""
alt_db = self.get_connection_string("sqlatest2.db")
class MultiEngineTask(self.SQLATask):
connection_string = alt_db
task0, task1, task2 = BaseTask(), self.SQLATask(), MultiEngineTask()
self.assertTrue(task1.output().engine != task2.output().engine)
luigi.build([task2, task1, task0], local_scheduler=True, workers=self.NUM_WORKERS)
self._check_entries(task1.output().engine)
self._check_entries(task2.output().engine) | Test case where different tasks require different SQL engines. | test_multiple_engines | python | spotify/luigi | test/contrib/sqla_test.py | https://github.com/spotify/luigi/blob/master/test/contrib/sqla_test.py | Apache-2.0 |
def test_check_output(self):
""" Test check_output ssh
Assumes the running user can ssh to working_ssh_host
"""
output = self.context.check_output(["echo", "-n", "luigi"])
self.assertEqual(output, b"luigi") | Test check_output ssh
Assumes the running user can ssh to working_ssh_host | test_check_output | python | spotify/luigi | test/contrib/test_ssh.py | https://github.com/spotify/luigi/blob/master/test/contrib/test_ssh.py | Apache-2.0 |
def generate_task_families(task_class, n):
"""
Generate n copies of a task with different task_family names.
:param task_class: a subclass of `luigi.Task`
:param n: number of copies of `task_class` to create
:return: Dictionary of task_family => task_class
"""
ret = {}
for i in range(n):
class_name = '{}_{}'.format(task_class.task_family, i)
ret[class_name] = type(class_name, (task_class,), {})
return ret | Generate n copies of a task with different task_family names.
:param task_class: a subclass of `luigi.Task`
:param n: number of copies of `task_class` to create
:return: Dictionary of task_family => task_class | generate_task_families | python | spotify/luigi | test/visualiser/visualiser_test.py | https://github.com/spotify/luigi/blob/master/test/visualiser/visualiser_test.py | Apache-2.0 |
def popmin(a, b):
"""
popmin(a, b) -> (i, a', b')
where i is min(a[0], b[0]) and a'/b' are the results of removing i from the
relevant sequence.
"""
if len(a) == 0:
return b[0], a, b[1:]
elif len(b) == 0:
return a[0], a[1:], b
elif a[0] > b[0]:
return b[0], a, b[1:]
else:
return a[0], a[1:], b | popmin(a, b) -> (i, a', b')
where i is min(a[0], b[0]) and a'/b' are the results of removing i from the
relevant sequence. | popmin | python | spotify/luigi | test/visualiser/visualiser_test.py | https://github.com/spotify/luigi/blob/master/test/visualiser/visualiser_test.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, it expects a file to be present in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.contrib.hdfs.HdfsTarget(self.date.strftime('/tmp/text/%Y-%m-%d.txt')) | Returns the target output for this task.
In this case, it expects a file to be present in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/wordcount_hadoop.py | https://github.com/spotify/luigi/blob/master/examples/wordcount_hadoop.py | Apache-2.0 |
def requires(self):
"""
This task's dependencies:
* :py:class:`~.InputText`
:return: list of object (:py:class:`luigi.task.Task`)
"""
return [InputText(date) for date in self.date_interval.dates()] | This task's dependencies:
* :py:class:`~.InputText`
:return: list of object (:py:class:`luigi.task.Task`) | requires | python | spotify/luigi | examples/wordcount_hadoop.py | https://github.com/spotify/luigi/blob/master/examples/wordcount_hadoop.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.contrib.hdfs.HdfsTarget('/tmp/text-count/%s' % self.date_interval) | Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/wordcount_hadoop.py | https://github.com/spotify/luigi/blob/master/examples/wordcount_hadoop.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`)
"""
return luigi.contrib.hdfs.HdfsTarget(self.terasort_in) | Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`) | output | python | spotify/luigi | examples/terasort.py | https://github.com/spotify/luigi/blob/master/examples/terasort.py | Apache-2.0 |
def requires(self):
"""
This task's dependencies:
* :py:class:`~.TeraGen`
:return: object (:py:class:`luigi.task.Task`)
"""
return TeraGen(terasort_in=self.terasort_in) | This task's dependencies:
* :py:class:`~.TeraGen`
:return: object (:py:class:`luigi.task.Task`) | requires | python | spotify/luigi | examples/terasort.py | https://github.com/spotify/luigi/blob/master/examples/terasort.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`)
"""
return luigi.contrib.hdfs.HdfsTarget(self.terasort_out) | Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`) | output | python | spotify/luigi | examples/terasort.py | https://github.com/spotify/luigi/blob/master/examples/terasort.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`)
"""
time.sleep(1)
return luigi.LocalTarget('/tmp/bar/%d' % self.num) | Returns the target output for this task.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`) | output | python | spotify/luigi | examples/foo.py | https://github.com/spotify/luigi/blob/master/examples/foo.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.LocalTarget('/tmp/Config_%d.txt' % self.seed) | Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/dynamic_requirements.py | https://github.com/spotify/luigi/blob/master/examples/dynamic_requirements.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.LocalTarget('/tmp/Data_%d.txt' % self.magic_number) | Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/dynamic_requirements.py | https://github.com/spotify/luigi/blob/master/examples/dynamic_requirements.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.LocalTarget('/tmp/Dynamic_%d.txt' % self.seed) | Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/dynamic_requirements.py | https://github.com/spotify/luigi/blob/master/examples/dynamic_requirements.py | Apache-2.0 |
def run(self):
"""
Writes data in JSON format into the task's output target.
The data objects have the following attributes:
* `_id` is the default Elasticsearch id field,
* `text`: the text,
* `date`: the day when the data was created.
"""
today = datetime.date.today()
with self.output().open('w') as output:
for i in range(5):
output.write(json.dumps({'_id': i, 'text': 'Hi %s' % i,
'date': str(today)}))
output.write('\n') | Writes data in JSON format into the task's output target.
The data objects have the following attributes:
* `_id` is the default Elasticsearch id field,
* `text`: the text,
* `date`: the day when the data was created. | run | python | spotify/luigi | examples/elasticsearch_index.py | https://github.com/spotify/luigi/blob/master/examples/elasticsearch_index.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.LocalTarget(path='/tmp/_docs-%s.ldj' % self.date) | Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/elasticsearch_index.py | https://github.com/spotify/luigi/blob/master/examples/elasticsearch_index.py | Apache-2.0 |
def requires(self):
"""
This task's dependencies:
* :py:class:`~.FakeDocuments`
:return: object (:py:class:`luigi.task.Task`)
"""
return FakeDocuments() | This task's dependencies:
* :py:class:`~.FakeDocuments`
:return: object (:py:class:`luigi.task.Task`) | requires | python | spotify/luigi | examples/elasticsearch_index.py | https://github.com/spotify/luigi/blob/master/examples/elasticsearch_index.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, it expects a file to be present in the local file system.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.LocalTarget(self.date.strftime('/var/tmp/text/%Y-%m-%d.txt')) | Returns the target output for this task.
In this case, it expects a file to be present in the local file system.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/wordcount.py | https://github.com/spotify/luigi/blob/master/examples/wordcount.py | Apache-2.0 |
def requires(self):
"""
This task's dependencies:
* :py:class:`~.InputText`
:return: list of object (:py:class:`luigi.task.Task`)
"""
return [InputText(date) for date in self.date_interval.dates()] | This task's dependencies:
* :py:class:`~.InputText`
:return: list of object (:py:class:`luigi.task.Task`) | requires | python | spotify/luigi | examples/wordcount.py | https://github.com/spotify/luigi/blob/master/examples/wordcount.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.LocalTarget('/var/tmp/text-count/%s' % self.date_interval) | Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/wordcount.py | https://github.com/spotify/luigi/blob/master/examples/wordcount.py | Apache-2.0 |
def run(self):
"""
1. count the words for each of the :py:meth:`~.InputText.output` targets created by :py:class:`~.InputText`
2. write the count into the :py:meth:`~.WordCount.output` target
"""
count = {}
# NOTE: self.input() actually returns an element for the InputText.output() target
for f in self.input(): # The input() method is a wrapper around requires() that returns Target objects
for line in f.open('r'): # Target objects are a file system/format abstraction and this will return a file stream object
for word in line.strip().split():
count[word] = count.get(word, 0) + 1
# output data
f = self.output().open('w')
for word, count in count.items():
f.write("%s\t%d\n" % (word, count))
f.close() # WARNING: file system operations are atomic therefore if you don't close the file you lose all data | 1. count the words for each of the :py:meth:`~.InputText.output` targets created by :py:class:`~.InputText`
2. write the count into the :py:meth:`~.WordCount.output` target | run | python | spotify/luigi | examples/wordcount.py | https://github.com/spotify/luigi/blob/master/examples/wordcount.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file that will be created in a FTP server.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`)
"""
return RemoteTarget('/experiment/output1.txt', HOST, username=USER, password=PWD) | Returns the target output for this task.
In this case, a successful execution of this task will create a file that will be created in a FTP server.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`) | output | python | spotify/luigi | examples/ftp_experiment_outputs.py | https://github.com/spotify/luigi/blob/master/examples/ftp_experiment_outputs.py | Apache-2.0 |
def run(self):
"""
The execution of this task will write 4 lines of data on this task's target output.
"""
with self.output().open('w') as outfile:
print("data 0 200 10 50 60", file=outfile)
print("data 1 190 9 52 60", file=outfile)
print("data 2 200 10 52 60", file=outfile)
print("data 3 195 1 52 60", file=outfile) | The execution of this task will write 4 lines of data on this task's target output. | run | python | spotify/luigi | examples/ftp_experiment_outputs.py | https://github.com/spotify/luigi/blob/master/examples/ftp_experiment_outputs.py | Apache-2.0 |
def requires(self):
"""
This task's dependencies:
* :py:class:`~.ExperimentTask`
:return: object (:py:class:`luigi.task.Task`)
"""
return ExperimentTask() | This task's dependencies:
* :py:class:`~.ExperimentTask`
:return: object (:py:class:`luigi.task.Task`) | requires | python | spotify/luigi | examples/ftp_experiment_outputs.py | https://github.com/spotify/luigi/blob/master/examples/ftp_experiment_outputs.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`)
"""
return luigi.LocalTarget('/tmp/processeddata.txt') | Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`) | output | python | spotify/luigi | examples/ftp_experiment_outputs.py | https://github.com/spotify/luigi/blob/master/examples/ftp_experiment_outputs.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, it expects a file to be present in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.contrib.hdfs.HdfsTarget(self.date.strftime('data/streams_%Y-%m-%d.tsv')) | Returns the target output for this task.
In this case, it expects a file to be present in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/top_artists.py | https://github.com/spotify/luigi/blob/master/examples/top_artists.py | Apache-2.0 |
def run(self):
"""
Generates bogus data and writes it into the :py:meth:`~.Streams.output` target.
"""
with self.output().open('w') as output:
for _ in range(1000):
output.write('{} {} {}\n'.format(
random.randint(0, 999),
random.randint(0, 999),
random.randint(0, 999))) | Generates bogus data and writes it into the :py:meth:`~.Streams.output` target. | run | python | spotify/luigi | examples/top_artists.py | https://github.com/spotify/luigi/blob/master/examples/top_artists.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file in the local file system.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.LocalTarget(self.date.strftime('data/streams_%Y_%m_%d_faked.tsv')) | Returns the target output for this task.
In this case, a successful execution of this task will create a file in the local file system.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/top_artists.py | https://github.com/spotify/luigi/blob/master/examples/top_artists.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.contrib.hdfs.HdfsTarget(self.date.strftime('data/streams_%Y_%m_%d_faked.tsv')) | Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/top_artists.py | https://github.com/spotify/luigi/blob/master/examples/top_artists.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.LocalTarget("data/artist_streams_{}.tsv".format(self.date_interval)) | Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/top_artists.py | https://github.com/spotify/luigi/blob/master/examples/top_artists.py | Apache-2.0 |
def requires(self):
"""
This task's dependencies:
* :py:class:`~.Streams`
:return: list of object (:py:class:`luigi.task.Task`)
"""
return [Streams(date) for date in self.date_interval] | This task's dependencies:
* :py:class:`~.Streams`
:return: list of object (:py:class:`luigi.task.Task`) | requires | python | spotify/luigi | examples/top_artists.py | https://github.com/spotify/luigi/blob/master/examples/top_artists.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.contrib.hdfs.HdfsTarget("data/artist_streams_%s.tsv" % self.date_interval) | Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/top_artists.py | https://github.com/spotify/luigi/blob/master/examples/top_artists.py | Apache-2.0 |
def requires(self):
"""
This task's dependencies:
* :py:class:`~.StreamsHdfs`
:return: list of object (:py:class:`luigi.task.Task`)
"""
return [StreamsHdfs(date) for date in self.date_interval] | This task's dependencies:
* :py:class:`~.StreamsHdfs`
:return: list of object (:py:class:`luigi.task.Task`) | requires | python | spotify/luigi | examples/top_artists.py | https://github.com/spotify/luigi/blob/master/examples/top_artists.py | Apache-2.0 |
def requires(self):
"""
This task's dependencies:
* :py:class:`~.AggregateArtists` or
* :py:class:`~.AggregateArtistsSpark` if :py:attr:`~/.Top10Artists.use_spark` is set.
:return: object (:py:class:`luigi.task.Task`)
"""
if self.use_spark:
return AggregateArtistsSpark(self.date_interval)
else:
return AggregateArtists(self.date_interval) | This task's dependencies:
* :py:class:`~.AggregateArtists` or
* :py:class:`~.AggregateArtistsSpark` if :py:attr:`~/.Top10Artists.use_spark` is set.
:return: object (:py:class:`luigi.task.Task`) | requires | python | spotify/luigi | examples/top_artists.py | https://github.com/spotify/luigi/blob/master/examples/top_artists.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.LocalTarget("data/top_artists_%s.tsv" % self.date_interval) | Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`) | output | python | spotify/luigi | examples/top_artists.py | https://github.com/spotify/luigi/blob/master/examples/top_artists.py | Apache-2.0 |
def requires(self):
"""
This task's dependencies:
* :py:class:`~.Top10Artists`
:return: list of object (:py:class:`luigi.task.Task`)
"""
return Top10Artists(self.date_interval, self.use_spark) | This task's dependencies:
* :py:class:`~.Top10Artists`
:return: list of object (:py:class:`luigi.task.Task`) | requires | python | spotify/luigi | examples/top_artists.py | https://github.com/spotify/luigi/blob/master/examples/top_artists.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file on a remote server using SSH.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`)
"""
return RemoteTarget(
"/tmp/stuff",
SSH_HOST
) | Returns the target output for this task.
In this case, a successful execution of this task will create a file on a remote server using SSH.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`) | output | python | spotify/luigi | examples/ssh_remote_execution.py | https://github.com/spotify/luigi/blob/master/examples/ssh_remote_execution.py | Apache-2.0 |
def requires(self):
"""
This task's dependencies:
* :py:class:`~.CreateRemoteData`
:return: object (:py:class:`luigi.task.Task`)
"""
return CreateRemoteData() | This task's dependencies:
* :py:class:`~.CreateRemoteData`
:return: object (:py:class:`luigi.task.Task`) | requires | python | spotify/luigi | examples/ssh_remote_execution.py | https://github.com/spotify/luigi/blob/master/examples/ssh_remote_execution.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will simulate the creation of a file in a filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`)
"""
return MockTarget("output", mirror_on_stderr=True) | Returns the target output for this task.
In this case, a successful execution of this task will simulate the creation of a file in a filesystem.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`) | output | python | spotify/luigi | examples/ssh_remote_execution.py | https://github.com/spotify/luigi/blob/master/examples/ssh_remote_execution.py | Apache-2.0 |
def run(self):
"""
Generates :py:attr:`~.UserItemMatrix.data_size` elements.
Writes this data in \\ separated value format into the target :py:func:`~/.UserItemMatrix.output`.
The data has the following elements:
* `user` is the default Elasticsearch id field,
* `track`: the text,
* `rating`: the day when the data was created.
"""
w = self.output().open('w')
for user in range(self.data_size):
track = int(random.random() * self.data_size)
w.write('%d\\%d\\%f' % (user, track, 1.0))
w.close() | Generates :py:attr:`~.UserItemMatrix.data_size` elements.
Writes this data in \\ separated value format into the target :py:func:`~/.UserItemMatrix.output`.
The data has the following elements:
* `user` is the default Elasticsearch id field,
* `track`: the text,
* `rating`: the day when the data was created. | run | python | spotify/luigi | examples/spark_als.py | https://github.com/spotify/luigi/blob/master/examples/spark_als.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`)
"""
return luigi.contrib.hdfs.HdfsTarget('data-matrix', format=luigi.format.Gzip) | Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`) | output | python | spotify/luigi | examples/spark_als.py | https://github.com/spotify/luigi/blob/master/examples/spark_als.py | Apache-2.0 |
def requires(self):
"""
This task's dependencies:
* :py:class:`~.UserItemMatrix`
:return: object (:py:class:`luigi.task.Task`)
"""
return UserItemMatrix(self.data_size) | This task's dependencies:
* :py:class:`~.UserItemMatrix`
:return: object (:py:class:`luigi.task.Task`) | requires | python | spotify/luigi | examples/spark_als.py | https://github.com/spotify/luigi/blob/master/examples/spark_als.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`)
"""
# The corresponding Spark job outputs as GZip format.
return luigi.contrib.hdfs.HdfsTarget('als-output/', format=luigi.format.Gzip) | Returns the target output for this task.
In this case, a successful execution of this task will create a file in HDFS.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`) | output | python | spotify/luigi | examples/spark_als.py | https://github.com/spotify/luigi/blob/master/examples/spark_als.py | Apache-2.0 |
def output(self):
"""
Returns the target output for this task.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`)
"""
time.sleep(1)
return luigi.LocalTarget('/tmp/bar/%d' % self.num) | Returns the target output for this task.
:return: the target output for this task.
:rtype: object (:py:class:`~luigi.target.Target`) | output | python | spotify/luigi | examples/foo_complex.py | https://github.com/spotify/luigi/blob/master/examples/foo_complex.py | Apache-2.0 |
def load_stop_words(stop_word_file):
"""
Utility function to load stop words from a file and return as a list of words
@param stop_word_file Path and file name of a file containing stop words.
@return list A list of stop words.
"""
stop_words = []
for line in open(stop_word_file):
if line.strip()[0:1] != "#":
for word in line.split(): # in case more than one per line
stop_words.append(word)
return stop_words | Utility function to load stop words from a file and return as a list of words
@param stop_word_file Path and file name of a file containing stop words.
@return list A list of stop words. | load_stop_words | python | aneesha/RAKE | rake.py | https://github.com/aneesha/RAKE/blob/master/rake.py | MIT |
def separate_words(text, min_word_return_size):
"""
Utility function to return a list of all words that are have a length greater than a specified number of characters.
@param text The text that must be split in to words.
@param min_word_return_size The minimum no of characters a word must have to be included.
"""
splitter = re.compile('[^a-zA-Z0-9_\\+\\-/]')
words = []
for single_word in splitter.split(text):
current_word = single_word.strip().lower()
#leave numbers in phrase, but don't count as words, since they tend to invalidate scores of their phrases
if len(current_word) > min_word_return_size and current_word != '' and not is_number(current_word):
words.append(current_word)
return words | Utility function to return a list of all words that are have a length greater than a specified number of characters.
@param text The text that must be split in to words.
@param min_word_return_size The minimum no of characters a word must have to be included. | separate_words | python | aneesha/RAKE | rake.py | https://github.com/aneesha/RAKE/blob/master/rake.py | MIT |
def split_sentences(text):
"""
Utility function to return a list of sentences.
@param text The text that must be split in to sentences.
"""
sentence_delimiters = re.compile(u'[.!?,;:\t\\\\"\\(\\)\\\'\u2019\u2013]|\\s\\-\\s')
sentences = sentence_delimiters.split(text)
return sentences | Utility function to return a list of sentences.
@param text The text that must be split in to sentences. | split_sentences | python | aneesha/RAKE | rake.py | https://github.com/aneesha/RAKE/blob/master/rake.py | MIT |
def count_nodes() -> int:
"""Count number of references to DOMNodes."""
dom_nodes = [
obj
for obj in gc.get_objects()
if any(cls.__name__ == "DOMNode" for cls in obj.__class__.__mro__)
]
print(dom_nodes)
return len(dom_nodes) | Count number of references to DOMNodes. | count_nodes | python | Textualize/textual | tests/test_gc.py | https://github.com/Textualize/textual/blob/master/tests/test_gc.py | MIT |
async def run_app() -> None:
"""Run a dummy app."""
class DummyApp(App):
"""Dummy app with a few widgets."""
def compose(self) -> ComposeResult:
yield Header()
with Vertical():
yield Label("foo")
yield Label("bar")
yield Footer()
app = DummyApp()
async with app.run_test() as pilot:
# We should have a bunch of DOMNodes while the test is running
assert count_nodes() > 0
await pilot.press("ctrl+c")
assert not app._running
# Force a GC collection
gc.collect()
# After the test, all DOMNodes will have been torn down
assert count_nodes() == 1 | Run a dummy app. | run_app | python | Textualize/textual | tests/test_gc.py | https://github.com/Textualize/textual/blob/master/tests/test_gc.py | MIT |
async def _count_app_nodes() -> None:
"""Regression test for https://github.com/Textualize/textual/issues/4959"""
# Should be no DOMNodes yet
assert count_nodes() == 0
await run_app()
await asyncio.sleep(0)
gc.collect()
nodes_remaining = count_nodes()
if nodes_remaining:
print("NODES REMAINING")
import objgraph
objgraph.show_backrefs(
[
obj
for obj in gc.get_objects()
if any(cls.__name__ == "App" for cls in obj.__class__.__mro__)
],
filename="graph.png",
max_depth=15,
)
assert nodes_remaining == 0 | Regression test for https://github.com/Textualize/textual/issues/4959 | _count_app_nodes | python | Textualize/textual | tests/test_gc.py | https://github.com/Textualize/textual/blob/master/tests/test_gc.py | MIT |
async def test_gc():
"""Regression test for https://github.com/Textualize/textual/issues/4959"""
await _count_app_nodes() | Regression test for https://github.com/Textualize/textual/issues/4959 | test_gc | python | Textualize/textual | tests/test_gc.py | https://github.com/Textualize/textual/blob/master/tests/test_gc.py | MIT |
async def test_render_only_after_mount():
"""Regression test for https://github.com/Textualize/textual/issues/2914"""
app = App()
async with app.run_test() as pilot:
app.mount(W())
app.mount(W())
await pilot.pause() | Regression test for https://github.com/Textualize/textual/issues/2914 | test_render_only_after_mount | python | Textualize/textual | tests/test_mount.py | https://github.com/Textualize/textual/blob/master/tests/test_mount.py | MIT |
async def test_just_app_no_bindings() -> None:
"""An app with no bindings should have no bindings, other than the app's hard-coded ones."""
async with NoBindings().run_test() as pilot:
assert list(pilot.app._bindings.key_to_bindings.keys()) == [
"ctrl+q",
"ctrl+c",
"ctrl+p",
]
assert pilot.app._bindings.get_bindings_for_key("ctrl+q")[0].priority is True | An app with no bindings should have no bindings, other than the app's hard-coded ones. | test_just_app_no_bindings | python | Textualize/textual | tests/test_binding_inheritance.py | https://github.com/Textualize/textual/blob/master/tests/test_binding_inheritance.py | MIT |
async def test_just_app_alpha_binding() -> None:
"""An app with a single binding should have just the one binding."""
async with AlphaBinding().run_test() as pilot:
assert sorted(pilot.app._bindings.key_to_bindings.keys()) == sorted(
["ctrl+c", "ctrl+p", "ctrl+q", "a"]
)
assert pilot.app._bindings.get_bindings_for_key("ctrl+q")[0].priority is True
assert pilot.app._bindings.get_bindings_for_key("a")[0].priority is True | An app with a single binding should have just the one binding. | test_just_app_alpha_binding | python | Textualize/textual | tests/test_binding_inheritance.py | https://github.com/Textualize/textual/blob/master/tests/test_binding_inheritance.py | MIT |
async def test_just_app_low_priority_alpha_binding() -> None:
"""An app with a single low-priority binding should have just the one binding."""
async with LowAlphaBinding().run_test() as pilot:
assert sorted(pilot.app._bindings.key_to_bindings.keys()) == sorted(
["ctrl+c", "ctrl+p", "ctrl+q", "a"]
)
assert pilot.app._bindings.get_bindings_for_key("ctrl+q")[0].priority is True
assert pilot.app._bindings.get_bindings_for_key("a")[0].priority is False | An app with a single low-priority binding should have just the one binding. | test_just_app_low_priority_alpha_binding | python | Textualize/textual | tests/test_binding_inheritance.py | https://github.com/Textualize/textual/blob/master/tests/test_binding_inheritance.py | MIT |
async def test_app_screen_with_bindings() -> None:
"""Test a screen with a single key binding defined."""
async with AppWithScreenThatHasABinding().run_test() as pilot:
assert pilot.app.screen._bindings.get_bindings_for_key("a")[0].priority is True | Test a screen with a single key binding defined. | test_app_screen_with_bindings | python | Textualize/textual | tests/test_binding_inheritance.py | https://github.com/Textualize/textual/blob/master/tests/test_binding_inheritance.py | MIT |
async def test_app_screen_with_low_bindings() -> None:
"""Test a screen with a single low-priority key binding defined."""
async with AppWithScreenThatHasALowBinding().run_test() as pilot:
assert pilot.app.screen._bindings.get_bindings_for_key("a")[0].priority is False | Test a screen with a single low-priority key binding defined. | test_app_screen_with_low_bindings | python | Textualize/textual | tests/test_binding_inheritance.py | https://github.com/Textualize/textual/blob/master/tests/test_binding_inheritance.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.