示例#1
0
    def test_parameter_parse_and_default(self):
        month = luigi.date_interval.Month(2012, 11)
        other = luigi.date_interval.Month(2012, 10)

        class MyTask(luigi.Task):
            di = DI(default=month)

        class MyTaskNoDefault(luigi.Task):
            di = DI()

        self.assertEqual(MyTask().di, month)
        in_parse(["MyTask", "--di", "2012-10"],
                 lambda task: self.assertEqual(task.di, other))
        task = MyTask(month)
        self.assertEqual(task.di, month)
        task = MyTask(di=month)
        self.assertEqual(task.di, month)
        task = MyTask(other)
        self.assertNotEqual(task.di, month)

        def fail1():
            return MyTaskNoDefault()

        self.assertRaises(luigi.parameter.MissingParameterException, fail1)

        in_parse(["MyTaskNoDefault", "--di", "2012-10"],
                 lambda task: self.assertEqual(task.di, other))
示例#2
0
    def test_parameter_parse_and_default(self):
        month = luigi.date_interval.Month(2012, 11)
        other = luigi.date_interval.Month(2012, 10)

        class MyTask(luigi.Task):
            di = DI(default=month)

        class MyTaskNoDefault(luigi.Task):
            di = DI()

        self.assertEqual(MyTask().di, month)
        in_parse(["MyTask", "--di", "2012-10"],
                 lambda task: self.assertEqual(task.di, other))
        task = MyTask(month)
        self.assertEqual(task.di, month)
        task = MyTask(di=month)
        self.assertEqual(task.di, month)
        task = MyTask(other)
        self.assertNotEqual(task.di, month)

        def fail1():
            return MyTaskNoDefault()
        self.assertRaises(luigi.parameter.MissingParameterException, fail1)

        in_parse(["MyTaskNoDefault", "--di", "2012-10"],
                 lambda task: self.assertEqual(task.di, other))
示例#3
0
    def test_subclasses(self):
        class BarBaseClass(luigi.Task):
            x = luigi.Parameter(default="bar_base_default")

        class BarSubClass(BarBaseClass):
            pass

        in_parse(["BarSubClass", "--x", "xyz", "--BarBaseClass-x", "xyz"], lambda task: self.assertEqual(task.x, "xyz"))

        # https://github.com/spotify/luigi/issues/822#issuecomment-77782714
        in_parse(["BarBaseClass", "--BarBaseClass-x", "xyz"], lambda task: self.assertEqual(task.x, "xyz"))
示例#4
0
    def test_subclasses(self):
        class BarBaseClass(luigi.Task):
            x = luigi.Parameter(default='bar_base_default')

        class BarSubClass(BarBaseClass):
            pass

        in_parse(['BarSubClass', '--x', 'xyz', '--BarBaseClass-x', 'xyz'],
                 lambda task: self.assertEqual(task.x, 'xyz'))

        # https://github.com/spotify/luigi/issues/822#issuecomment-77782714
        in_parse(['BarBaseClass', '--BarBaseClass-x', 'xyz'],
                 lambda task: self.assertEqual(task.x, 'xyz'))
示例#5
0
 def test_parse_interface(self):
     in_parse([
         "DictParameterTask", "--param",
         '{"username": "******", "password": "******"}'
     ], lambda task: self.assertEqual(task.param, DictParameterTest._dict))
示例#6
0
 def test_parse_interface(self):
     in_parse(["DateHourTask", "--dh", "2013-02-01T18"],
              lambda task: self.assertEqual(
                  task.dh, datetime.datetime(2013, 2, 1, 18, 0, 0)))
示例#7
0
 def test_parse_interface(self):
     in_parse(
         ["DateTask", "--day", "2015-04-03"],
         lambda task: self.assertEqual(task.day, datetime.date(2015, 4, 3)))
示例#8
0
 def test_parse_interface(self):
     in_parse([
         "YearTask", "--year", "2015"
     ], lambda task: self.assertEqual(task.year, datetime.date(2015, 1, 1)))
示例#9
0
 def test_parse_interface(self):
     in_parse(["MonthTask", "--month", "2015-04"],
              lambda task: self.assertEqual(task.month,
                                            datetime.date(2015, 4, 1)))
示例#10
0
 def test_parse_interface(self):
     in_parse(["DateSecondTask", "--ds", "2013-02-01T184227"],
              lambda task: self.assertEqual(
                  task.ds, datetime.datetime(2013, 2, 1, 18, 42, 27)))
示例#11
0
 def test_parse_interface(self):
     in_parse(["DateHourTask", "--dh", "2013-02-01T18"],
              lambda task: self.assertEqual(task.dh, datetime.datetime(2013, 2, 1, 18, 0, 0)))
示例#12
0
 def test_parse_interface(self):
     in_parse(["DateTask", "--day", "2015-04-03"],
              lambda task: self.assertEqual(task.day, datetime.date(2015, 4, 3)))
示例#13
0
 def test_parse_interface(self):
     in_parse(["YearTask", "--year", "2015"],
              lambda task: self.assertEqual(task.year, datetime.date(2015, 1, 1)))
示例#14
0
 def test_parse_interface(self):
     in_parse(["MonthTask", "--month", "2015-04"],
              lambda task: self.assertEqual(task.month, datetime.date(2015, 4, 1)))
示例#15
0
 def test_parse_interface(self):
     in_parse(["DateMinuteTask", "--dm", "2013-02-01T1842"],
              lambda task: self.assertEqual(task.dm, datetime.datetime(2013, 2, 1, 18, 42, 0)))
示例#16
0
 def test_parse_interface(self):
     in_parse(["DateSecondTask", "--ds", "2013-02-01T184227"],
              lambda task: self.assertEqual(task.ds, datetime.datetime(2013, 2, 1, 18, 42, 27)))
示例#17
0
 def test_parse_interface(self):
     in_parse(["DateMinuteTask", "--dm", "2013-02-01T1842"],
              lambda task: self.assertEqual(
                  task.dm, datetime.datetime(2013, 2, 1, 18, 42, 0)))
示例#18
0
 def test_parse_interface(self):
     in_parse(["DictParameterTask", "--param", '{"username": "******", "password": "******"}'],
              lambda task: self.assertEqual(task.param, DictParameterTest._dict))