#   Copyright 2015 Ufora Inc.
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

import unittest
import pyfora
import ufora.config.Setup as Setup
import ufora.FORA.python.PurePython.DictTestCases as DictTestCases
import ufora.FORA.python.PurePython.ListTestCases as ListTestCases
import ufora.FORA.python.PurePython.TupleTestCases as TupleTestCases
import ufora.FORA.python.PurePython.ExecutorTestCommon as ExecutorTestCommon


import ufora.test.ClusterSimulation as ClusterSimulation


class ExecutorSimulationTest(
        unittest.TestCase,
        ExecutorTestCommon.ExecutorTestCommon,
        DictTestCases.DictTestCases,
        ListTestCases.ListTestCases,
        TupleTestCases.TupleTestCases):
    @classmethod
    def setUpClass(cls):
        cls.config = Setup.config()
        cls.executor = None
        cls.simulation = ClusterSimulation.Simulator.createGlobalSimulator()
        cls.simulation.startService()
        cls.simulation.getDesirePublisher().desireNumberOfWorkers(1)

    @classmethod
    def tearDownClass(cls):
        cls.simulation.stopService()

    @classmethod
    def create_executor(cls, allowCached=True):
        if not allowCached:
            return pyfora.connect('http://localhost:30000')

        if cls.executor is None:
            cls.executor = pyfora.connect('http://localhost:30000')
            cls.executor.stayOpenOnExit = True
        return cls.executor


if __name__ == '__main__':
    import ufora.config.Mainline as Mainline
    Mainline.UnitTestMainline()


[((58, 4, 58, 31), 'ufora.config.Mainline.UnitTestMainline', 'Mainline.UnitTestMainline', ({}, {}), '()', True, 'import ufora.config.Mainline as Mainline\n'), ((35, 21, 35, 35), 'ufora.config.Setup.config', 'Setup.config', ({}, {}), '()', True, 'import ufora.config.Setup as Setup\n'), ((37, 25, 37, 76), 'ufora.test.ClusterSimulation.Simulator.createGlobalSimulator', 'ClusterSimulation.Simulator.createGlobalSimulator', ({}, {}), '()', True, 'import ufora.test.ClusterSimulation as ClusterSimulation\n'), ((48, 19, 48, 59), 'pyfora.connect', 'pyfora.connect', ({(48, 34, 48, 58): '"""http://localhost:30000"""'}, {}), "('http://localhost:30000')", False, 'import pyfora\n'), ((51, 27, 51, 67), 'pyfora.connect', 'pyfora.connect', ({(51, 42, 51, 66): '"""http://localhost:30000"""'}, {}), "('http://localhost:30000')", False, 'import pyfora\n')]