Exemplo n.º 1
0
    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'])
Exemplo n.º 2
0
    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')
Exemplo n.º 3
0
    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'])
Exemplo n.º 4
0
 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'),
         }
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
 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))
Exemplo n.º 8
0
    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()
Exemplo n.º 9
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 MockFile("output", mirror_on_stderr=True)
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
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())
Exemplo n.º 12
0
 def output(self):
     return MockFile(self.date.strftime('/tmp/copy-data-%Y-%m-%d.txt'))
Exemplo n.º 13
0
 def output(self):
     return MockFile('/%s/%u' % (self.__class__.__name__, self.param))
Exemplo n.º 14
0
 def _touch(self, path):
     t = MockFile(path)
     with t.open('w'):
         pass
Exemplo n.º 15
0
 def output(self):
     return MockFile("done.txt")
Exemplo n.º 16
0
 def output(self):
     return MockFile(
         self.dh.strftime('TaskB/%%s%Y-%m-%d/%H') % self.complicator)
Exemplo n.º 17
0
 def output(self):
     return MockFile(
         self.d.strftime(
             '/data/2014/p/v/z/%Y_/_%m-_-%doctor/20/ZOOO'))
Exemplo n.º 18
0
 def output(self):
     return MockFile("output", mirror_on_stderr=True)
Exemplo n.º 19
0
 def output(self):
     return MockFile("in-memory-paths")
Exemplo n.º 20
0
 def output(self):
     return MockFile(self.dh.strftime('not/a/real/path/%Y-%m-%d/%H'))
Exemplo n.º 21
0
 def output(self):
     return MockFile(
         self.d.strftime('/n2000y01a05n/%Y_%m-_-%daww/21mm01dara21/ooo'))
Exemplo n.º 22
0
 def output(self):
     return MockFile(self.dh.strftime('TaskA/%Y-%m-%d/%H'))
Exemplo n.º 23
0
 def output(self):
     return MockFile("MockInput")
Exemplo n.º 24
0
 def output(self):
     parameters.getParameters(self.sid, remote_storage_root)
     return MockFile("output", mirror_on_stderr=True)
Exemplo n.º 25
0
 def output(self):
     return MockFile('whatever')
Exemplo n.º 26
0
 def _touch(self, path):
     t = MockFile(path)
     with t.open('w'):
         pass
Exemplo n.º 27
0
 def test_mockfile(self):
     from luigi.mock import MockFile
     self.assertTrue(isinstance(MockFile('foo'), MockTarget))
Exemplo n.º 28
0
 def output(self):
     return MockFile("BaseTask", mirror_on_stderr=True)
Exemplo n.º 29
0
 def output(self):
     return MockFile('banana-%s-%s' % (self.x, self.y))
Exemplo n.º 30
0
 def output(self):
     return MockFile("MyOutput1")
Exemplo n.º 31
0
 def output(self):
     return MockFile("AddTaxiLocation")