Exemple #1
0
    def setUp(self):
        """Create a real client with some mocking."""
        self.client = Client()
        self.client.transport = MagicMock()
        peer = MagicMock()
        peer.host = "127.0.0.1"
        peer.port = 4000
        self.client.transport.getPeer = MagicMock(return_value=peer)
        self.client.factory = MagicMock()

        # Create the sharp engine
        sharp = SharpScript(self.client.factory.engine, self.client,
                MagicMock())
        sharp.bind_client(self.client)
        self.client.factory.sharp_engine = sharp

        def get_setting(address):
            """Private function to return a set of default settings."""
            default = {
                    "options.input.command_stacking": "",
                    "options.general.encoding": "latin-1",
            }
            return default[address]

        self.client.factory.engine.settings.__getitem__ = MagicMock(
                side_effect=get_setting)
Exemple #2
0
    def sharp_engine(self):
        if self._sharp_engine:
            return self._sharp_engine

        log.debug(
            f"Creating a SharpEngine for session {self.sid} (world: {'yes' if self.world else 'no'}, client: {'yes' if self.client else 'no'}, character: {'yes' if self.character else 'no'}, engine: {'yes' if self.engine else 'no'})"
        )
        self._sharp_engine = SharpScript(self.engine, self.client, self.world)
        return self._sharp_engine
Exemple #3
0
    def prepare_world(self, world, merge=None):
        """Prepare the world, creating appropriate values."""
        if not world.sharp_engine:
            sharp_engine = SharpScript(self, None, world)
            world.sharp_engine = sharp_engine

        if merge is not None:
            if merge == "ignore":
                world.merging = MergingMethod.ignore
            elif merge == "replace":
                world.merging = MergingMethod.replace
            else:
                raise ValueError("unkwno merging method: {}".format(
                        merge))
 def setUp(self):
     """Create the SharpScript instance."""
     self.engine = SharpScript(None, None, None)