async def test_switch_flag_changed(self):
        s1 = MockScript()
        sp1 = SingleScriptProvider(s1)

        s2 = MockScript()
        sp2 = SingleScriptProvider(s2)

        switched = SwitchedScriptProvider(sp1=sp1, sp2=sp2, _switch="test")
        async with switched:
            self.assertIs(await switched.get(test="sp2"), s2)
    async def test_get_s2(self):
        s1 = MockScript()
        sp1 = SingleScriptProvider(s1)

        s2 = MockScript()
        sp2 = SingleScriptProvider(s2)

        switched = SwitchedScriptProvider(sp1=sp1, sp2=sp2)
        async with switched:
            self.assertIs(await switched.get(type="sp2"), s2)
    async def test_fail_unknown_type(self):
        s1 = MockScript()
        sp1 = SingleScriptProvider(s1)

        s2 = MockScript()
        sp2 = SingleScriptProvider(s2)

        switched = SwitchedScriptProvider(sp1=sp1, sp2=sp2)
        async with switched:
            self.assertIsNone(await switched.get(type="sp_unknown"))
 async def test_non_owned(self):
     script = MockScript()
     single = SingleScriptProvider(script)
     async with script:
         async with single:
             pass
         self.assertTrue(script.acquired)
    async def test_get_script(self):
        c_client, c_server = pipe_bidi()

        ms = MockScript({"id": id(self)})
        sp = SingleScriptProvider(ms)

        rsps = RemoteScriptProviderServer(sp, c_server)
        rspc = RemoteScriptProvider(c_client)

        async with timeout_context(rsps, 10), timeout_context(rspc, 10):
            rsc = await rspc.get()
            async with timeout_context(rsc, 10):
                self.assertEqual(await wait_for(rsc.get_config("id"), 10),
                                 id(self))
Example #6
0
def VapourSynthScriptProvider():
    return SingleScriptProvider(VapourSynthScript(vpy_current_environment()), )
 async def test_always_same(self):
     script = MockScript()
     single = SingleScriptProvider(script)
     async with single:
         self.assertIs(script, await single.get())
         self.assertIs(script, await single.get())
 async def test_owner(self):
     script = MockScript()
     single = SingleScriptProvider(script)
     async with single:
         self.assertTrue(script.acquired)
     self.assertFalse(script.acquired)
Example #9
0
import asyncio
import os
import sys
from asyncio import ProactorEventLoop, wait_for

from aiounittest import AsyncTestCase

from yuuno2.providers.remote.client import RemoteScript
from yuuno2.providers.single import SingleScriptProvider
from yuuno2.tests.mocks import MockScript
from yuuno2server.subprocesses import SubprocessScript

MOCK_PROVIDER = lambda: SingleScriptProvider(
    MockScript({"test": f"{os.getppid()}"}))

if os.name == 'posix':

    def pid_exists(pid):
        """Check whether pid exists in the current process table."""
        import errno
        if pid < 0:
            return False
        try:
            os.kill(pid, 0)
        except OSError as e:
            return e.errno == errno.EPERM
        else:
            return True
else:

    def pid_exists(pid):