Ejemplo n.º 1
0
    def test_component(self):
        comp = set_as_top(self.factory.create('ASTestComp'))
        comp.set('x', 6)
        comp.set('y', 7)
        path = 'output'
        with comp.dir_context:
            with open(path, 'w') as out:
                out.write('Hello world!')
        comp.set('in_file', FileRef(path, comp))
        with comp.dir_context:
            os.remove(path)
        comp.run()
        self.assertEqual(comp.get('z'), 42.)
        with comp.get('out_file').open() as inp:
            data = inp.read()
        self.assertEqual(data, 'Hello world!')

        before = self.get_state(comp, 'the_obj', comp._client)
        state_file = 'state.pickle'
        try:
            comp.save(state_file)
            restored = Component.load(state_file)
            after = self.get_state(restored, 'the_obj', restored._client)
            restored.pre_delete()
            self.assertEqual(after, before)
        finally:
            os.remove(state_file)
            os.remove('AS-the_obj.in_file.dat')
            os.remove('AS-the_obj.out_file.dat')
        comp.pre_delete()

        comp = set_as_top(self.factory.create('ASTestComp'))
        comp.__del__()
Ejemplo n.º 2
0
    def test_component(self):
        logging.debug('')
        logging.debug('test_component')

        # We should get version 0.2 (with directory 'floyd').
        comp = set_as_top(self.factory.create('ASTestComp'))
        comp.set('x', 6)
        comp.set('y', 7)
        comp.set('obj_input.tof', 2.781828)
        comp.set('obj_input.subobj.sof', 3.14159)
        path = 'output'
        with comp.dir_context:
            with open(path, 'w') as out:
                out.write('Hello world!')
        comp.set('in_file', FileRef(path, comp))
        with comp.dir_context:
            os.remove(path)

        comp.run()

        exe_dir = comp.get('exe_dir')
        if sys.platform == 'win32':
            expected = r'floyd\\ASTestComp'  # Odd that backslash is repeated.
        else:
            expected = os.path.join('floyd', 'ASTestComp')
        print 'exe_dir', exe_dir
        print 'expected', expected
        self.assertTrue(exe_dir.endswith(expected))

        self.assertEqual(comp.get('z'), 42.)
        self.assertEqual(comp.get('obj_output.tof'), 2.781828)
        self.assertEqual(comp.get('obj_output.subobj.sof'), 3.14159)
        with comp.get('out_file').open() as inp:
            data = inp.read()
        self.assertEqual(data, 'Hello world!')

        result_b = comp.float_method()
        before = self.get_state(comp, 'the_obj', comp._client)
        state_file = 'state.pickle'
        try:
            comp.save(state_file)
            restored = Component.load(state_file)
            result_a = restored.float_method()
            after = self.get_state(restored, 'the_obj', restored._client)
            restored.pre_delete()
            self.assertEqual(result_a, result_b)
            self.compare_states(before, after)
        finally:
            os.remove(state_file)
            os.remove('AS-the_obj.in_file.dat')
            os.remove('AS-the_obj.out_file.dat')
            comp.pre_delete()
Ejemplo n.º 3
0
    def test_component(self):
        logging.debug('')
        logging.debug('test_component')

        # We should get version 0.2 (with directory 'floyd').
        comp = set_as_top(self.factory.create('ASTestComp'))
        comp.set('x', 6)
        comp.set('y', 7)
        comp.set('obj_input.tof', 2.781828)
        comp.set('obj_input.subobj.sof', 3.14159)
        path = 'output'
        with comp.dir_context:
            with open(path, 'w') as out:
                out.write('Hello world!')
        comp.set('in_file', FileRef(path, comp))
        with comp.dir_context:
            os.remove(path)

        comp.run()

        exe_dir = comp.get('exe_dir')
        if sys.platform == 'win32':
            expected = r'floyd\\ASTestComp'  # Odd that backslash is repeated.
        else:
            expected = os.path.join('floyd', 'ASTestComp')
        print 'exe_dir', exe_dir
        print 'expected', expected
        self.assertTrue(exe_dir.endswith(expected))

        self.assertEqual(comp.get('z'), 42.)
        self.assertEqual(comp.get('obj_output.tof'), 2.781828)
        self.assertEqual(comp.get('obj_output.subobj.sof'), 3.14159)
        with comp.get('out_file').open() as inp:
            data = inp.read()
        self.assertEqual(data, 'Hello world!')

        result_b = comp.float_method()
        before = self.get_state(comp, 'the_obj', comp._client)
        state_file = 'state.pickle'
        try:
            comp.save(state_file)
            restored = Component.load(state_file)
            result_a = restored.float_method()
            after = self.get_state(restored, 'the_obj', restored._client)
            restored.pre_delete()
            self.assertEqual(result_a, result_b)
            self.compare_states(before, after)
        finally:
            os.remove(state_file)
            os.remove('AS-the_obj.in_file.dat')
            os.remove('AS-the_obj.out_file.dat')
            comp.pre_delete()
Ejemplo n.º 4
0
    def test_component(self):
        logging.debug('')
        logging.debug('test_component')
        comp = set_as_top(self.factory.create('ASTestComp'))
        comp.set('x', 6)
        comp.set('y', 7)
        comp.set('obj_input.tof', 2.781828)
        comp.set('obj_input.subobj.sof', 3.14159)
        path = 'output'
        with comp.dir_context:
            with open(path, 'w') as out:
                out.write('Hello world!')
        comp.set('in_file', FileRef(path, comp))
        with comp.dir_context:
            os.remove(path)
        comp.run()
        self.assertEqual(comp.get('z'), 42.)
        self.assertEqual(comp.get('obj_output.tof'), 2.781828)
        self.assertEqual(comp.get('obj_output.subobj.sof'), 3.14159)
        with comp.get('out_file').open() as inp:
            data = inp.read()
        self.assertEqual(data, 'Hello world!')

        result_b = comp.float_method()
        before = self.get_state(comp, 'the_obj', comp._client)
        state_file = 'state.pickle'
        try:
            comp.save(state_file)
            restored = Component.load(state_file)
            result_a = restored.float_method()
            after = self.get_state(restored, 'the_obj', restored._client)
            restored.pre_delete()
            self.assertEqual(result_a, result_b)
            self.compare_states(before, after)
        finally:
            os.remove(state_file)
            os.remove('AS-the_obj.in_file.dat')
            os.remove('AS-the_obj.out_file.dat')
            comp.pre_delete()
Ejemplo n.º 5
0
    def test_component(self):
        logging.debug('')
        logging.debug('test_component')
        comp = set_as_top(self.factory.create('ASTestComp'))
        comp.set('x', 6)
        comp.set('y', 7)
        comp.set('obj_input.tof', 2.781828)
        comp.set('obj_input.subobj.sof', 3.14159)
        path = 'output'
        with comp.dir_context:
            with open(path, 'w') as out:
                out.write('Hello world!')
        comp.set('in_file', FileRef(path, comp))
        with comp.dir_context:
            os.remove(path)
        comp.run()
        self.assertEqual(comp.get('z'), 42.)
        self.assertEqual(comp.get('obj_output.tof'), 2.781828)
        self.assertEqual(comp.get('obj_output.subobj.sof'), 3.14159)
        with comp.get('out_file').open() as inp:
            data = inp.read()
        self.assertEqual(data, 'Hello world!')

        result_b = comp.float_method()
        before = self.get_state(comp, 'the_obj', comp._client)
        state_file = 'state.pickle'
        try:
            comp.save(state_file)
            restored = Component.load(state_file)
            result_a = restored.float_method()
            after = self.get_state(restored, 'the_obj', restored._client)
            restored.pre_delete()
            self.assertEqual(result_a, result_b)
            self.compare_states(before, after)
        finally:
            os.remove(state_file)
            os.remove('AS-the_obj.in_file.dat')
            os.remove('AS-the_obj.out_file.dat')
            comp.pre_delete()