def test_with(self): t = MockFile("foo") with t.open('w') as b: b.write("bar") with t.open('r') as b: self.assertEqual(list(b), ['bar'])
def test_unicode(self): t = MockFile("foo") with t.open('w') as b: b.write(u"bar") with t.open('r') as b: self.assertEqual(b.read(), u'bar')
def test_with(self): t = MockFile("foo") with t.open('w') as b: b.write("bar") with t.open('r') as b: self.assertEquals(list(b), ['bar'])
def output(self): base = self.dh.strftime('/even/%Y%m%d%H') if self.dh.hour % 2 == 0: return MockFile(base) else: return { 'spi': MockFile(base + '/something.spi'), 'spl': MockFile(base + '/something.spl'), }
def test_1(self): t = MockFile("test") p = t.open("w") print >> p, "test" p.close() q = t.open("r") self.assertEqual(list(q), ["test\n"]) q.close()
def test_1(self): t = MockFile('test') p = t.open('w') print >> p, 'test' p.close() q = t.open('r') self.assertEqual(list(q), ['test\n']) q.close()
def test_mockfile(self): from luigi.mock import MockFile if six.PY3: with self.assertWarnsRegex( DeprecationWarning, r'MockFile has been renamed MockTarget'): self.assertTrue(isinstance(MockFile('foo'), MockTarget)) else: self.assertTrue(isinstance(MockFile('foo'), MockTarget))
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 MockFile("output", mirror_on_stderr=True)
def test_missing_tasks_correctly_required(self): for task_path in task_a_paths: MockFile(task_path) task = RangeHourly(now=datetime_to_epoch(datetime.datetime(2016, 4, 1)), of='TaskA', start=datetime.datetime(2014, 3, 20, 17), task_limit=3, hours_back=3 * 365 * 24) # this test takes a few seconds. Since stop is not defined, finite_datetimes constitute many years to consider actual = [t.task_id for t in task.requires()] self.assertEqual(actual, expected_a)
class MockObject(Target): mock_file = MockFile('whatever') def exists(self): return True def write(self, obj): with self.mock_file.open('w') as _out: _out.write(pickle.dumps(obj)) def read(self): with self.mock_file.open('r') as _in: return pickle.reads(_in.read())
def output(self): return MockFile(self.date.strftime('/tmp/copy-data-%Y-%m-%d.txt'))
def output(self): return MockFile('/%s/%u' % (self.__class__.__name__, self.param))
def _touch(self, path): t = MockFile(path) with t.open('w'): pass
def output(self): return MockFile("done.txt")
def output(self): return MockFile( self.dh.strftime('TaskB/%%s%Y-%m-%d/%H') % self.complicator)
def output(self): return MockFile( self.d.strftime( '/data/2014/p/v/z/%Y_/_%m-_-%doctor/20/ZOOO'))
def output(self): return MockFile("output", mirror_on_stderr=True)
def output(self): return MockFile("in-memory-paths")
def output(self): return MockFile(self.dh.strftime('not/a/real/path/%Y-%m-%d/%H'))
def output(self): return MockFile( self.d.strftime('/n2000y01a05n/%Y_%m-_-%daww/21mm01dara21/ooo'))
def output(self): return MockFile(self.dh.strftime('TaskA/%Y-%m-%d/%H'))
def output(self): return MockFile("MockInput")
def output(self): parameters.getParameters(self.sid, remote_storage_root) return MockFile("output", mirror_on_stderr=True)
def output(self): return MockFile('whatever')
def test_mockfile(self): from luigi.mock import MockFile self.assertTrue(isinstance(MockFile('foo'), MockTarget))
def output(self): return MockFile("BaseTask", mirror_on_stderr=True)
def output(self): return MockFile('banana-%s-%s' % (self.x, self.y))
def output(self): return MockFile("MyOutput1")
def output(self): return MockFile("AddTaxiLocation")