Exemplo n.º 1
0
 def output_var(self, filename, pickle=False, backup=None):
     """ Adds output path which contains a python object,
     if directory is true a directory will will be created automatically
     """
     path = Variable(filename, self, pickle=pickle, backup=backup)
     assert path.get_path() not in self._sis_outputs
     self._sis_outputs[path.get_path()] = path
     return path
Exemplo n.º 2
0
    def test_ist_set(self):
        with tk.mktemp() as t1, tk.mktemp() as t2:
            var1 = Variable(t1)
            var2 = Variable(t2)
            c1 = var1 + 5
            c2 = c1 * 8
            c3 = c2 - (var2 % 5)
            c4 = c3.rformat('Hello {}')
            for i in [var1, var2, c1, c2, c3, c4]:
                self.assertEqual(i.is_set(), False)
            var1.set(3)
            for i in [var1, c1, c2]:
                self.assertEqual(i.is_set(), True)
            for i in [var2, c3, c4]:
                self.assertEqual(i.is_set(), False)
            var2.set(9)
            for i in [var1, var2, c1, c2, c3, c4]:
                self.assertEqual(i.is_set(), True)

            self.check_only_get_eq(var1, 3)
            self.check_only_get_eq(var2, 9)
            self.check_only_get_eq(c1, 8)
            self.check_only_get_eq(c2, 64)
            self.check_only_get_eq(c3, 60)
            self.check_only_get_eq(c4, 'Hello 60')
Exemplo n.º 3
0
    def test_path_delay(self):
        mjob = MockJob('test/me.1234')
        path = Path('lm.gz', mjob)

        self.check_only_get_eq(path, str(path))
        self.check_only_get_eq(path + '.foo', str(path) + '.foo')
        self.check_only_get_eq(path[:-3], str(path)[:-3])
        self.check_only_get_eq(path[-2], str(path)[-2])
        self.check_only_get_eq(path[:-3] + '.foo', str(path)[:-3] + '.foo')

        with tk.mktemp() as t:
            var = Variable(t)
            var.set(3)
            self.check_only_get_eq(var + 4, 7)
            self.check_only_get_eq(4 + var, 7)
            self.check_only_get_eq(var * 4, 12)
            self.check_only_get_eq(4 * var, 12)
Exemplo n.º 4
0
    def test_pickle(self):
        def pickle_and_check(path):
            with tk.mktemp() as pickle_path:
                with open(pickle_path, 'wb') as f:
                    pickle.dump(path, f)
                with open(pickle_path, 'rb') as f:
                    path_unpickled = pickle.load(f)
            self.assertEqual(path.__dict__, path_unpickled.__dict__)

        pickle_and_check(Path('out'))

        path = Path('lm.gz', MockJob('test/me.1234'))
        pickle_and_check(path)

        path = Path('lm.gz', MockJob('test/me.1234'), available=path_available_false)
        pickle_and_check(path)

        path = Variable('lm.gz', MockJob('test/me.1234'))
        pickle_and_check(path)
Exemplo n.º 5
0
    def test_fallback(self):
        with tk.mktemp() as t:
            var = Variable(t)
            self.assertEqual(var.is_set(), False)
            fallback = var.fallback(0)
            self.check_only_get_eq(fallback, 0)
            self.check_only_get_eq(fallback + 5, 5)
            var.set(3)
            self.assertEqual(var.is_set(), True)
            self.check_only_get_eq(fallback + 5, 8)

        with tk.mktemp() as t:
            var = Variable(t)
            var_chain = ((var + 4) % 2) * 42
            fallback = var_chain.rformat('{:05.1f}').fallback(0)
            self.assertEqual(var.is_set(), False)
            self.check_only_get_eq(fallback, 0)
            var.set(3)
            self.assertEqual(var.is_set(), True)
            self.check_only_get_eq(fallback, '042.0')