Exemplo n.º 1
0
    def test_constructor(self):
        p = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB)
        dir = ExecutionDirection('s')
        with self.assertRaises(TypeError):
            ProfileExecution()

        with self.assertRaises(TypeError):
            ProfileExecution(p)

        with self.assertRaises(TypeError):
            ProfileExecution(p, dir)

        with self.assertRaises(TypeError):
            ProfileExecution(p, dir, Options(p.supported_options))

        c = NullNSTSConnection()

        with self.assertRaises(TypeError):
            ProfileExecution(p, dir, Options(p.supported_options), float)

        with self.assertRaises(TypeError):
            ProfileExecution(p, dir, float, c)

        with self.assertRaises(TypeError):
            ProfileExecution(p, float, Options(p.supported_options), c)

        with self.assertRaises(TypeError):
            ProfileExecution(float, dir, Options(p.supported_options), c)

        ctx = ProfileExecution(p, dir, Options(p.supported_options), c)
Exemplo n.º 2
0
    def test_add_option(self):
        d = OptionsDescriptor()
        d.add_option('test', 'Hello', float)
        o = Options(d)

        self.assertLength(o, 1)
        self.assertLength(o.supported, 1)
        self.assertEqual(o.supported['test'].type, float)
        self.assertEqual(o.supported['test'].help, 'Hello')
        self.assertEqual(o.supported['test'].id, 'test')
        self.assertEqual(o.supported['test'].default, None)
        self.assertIsNone(o['test'])

        d = OptionsDescriptor()
        d.add_option('test', 'Hello', float)
        d.add_option('test2', 'Yeah', units.Time, 0)
        o = Options(d)

        self.assertLength(o, 2)
        self.assertLength(o.supported, 2)
        self.assertEqual(o.supported['test2'].type, units.Time)
        self.assertEqual(o.supported['test2'].help, 'Yeah')
        self.assertEqual(o.supported['test2'].id, 'test2')
        self.assertEqual(o.supported['test2'].default, units.Time(0))
        self.assertIsNone(o['test'])
        self.assertEqual(o['test2'], units.Time(0))
Exemplo n.º 3
0
    def __init__(self, profile, direction, profile_options={}):
        assert isinstance(profile, Profile)
        assert isinstance(direction, ExecutionDirection)

        self.__profile = profile
        self.__direction = direction
        self.__options = Options(SpeedTestOptionsDescriptor())
        self.__profile_options = Options(profile.supported_options,
                                         profile_options)
        self.samples = []
Exemplo n.º 4
0
    def test_empty_constructor(self):

        with self.assertRaises(TypeError):
            o = Options()

        d = OptionsDescriptor()
        o = Options(d)
        self.assertLength(o, 0)

        with self.assertRaises(UnknownOptionError):
            o['test']
Exemplo n.º 5
0
    def test_mutator(self):
        d = OptionsDescriptor()
        d.add_option('test', 'Hello', float)
        d.add_option('test2', 'Yeah', units.Time, 0)
        o = Options(d)

        with self.assertRaises(UnknownOptionError):
            o['unknown'] = 5

        o['test'] = 5
        self.assertEqual(o['test'], 5)

        o['test2'] = 7.1
        self.assertEqual(o['test2'], units.Time(7.1))

        # Request for impossible casting
        with self.assertRaises(TypeError):
            o['test2'] = units.BitRate(0)

        # Iterator access
        optids = []
        values = []
        for opt_id in o:
            optids.append(opt_id)
            values.append(o[opt_id])
        self.assertEqual(optids, ['test', 'test2'])
        self.assertEqual(values, [5, units.Time(7.1)])
Exemplo n.º 6
0
    def test_name(self):
        c = NullNSTSConnection()
        p = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB)
        dir = ExecutionDirection('s')
        opt = Options(p.supported_options)
        ctx = ProfileExecution(p, dir, opt, c)
        self.assertIsInstance(ctx.name, basestring)

        self.assertTrue(p.name in ctx.name)
Exemplo n.º 7
0
    def test_msg(self):
        p = Profile('profid', 'profname', ProfileExecutorA, ProfileExecutorB)
        c = NullNSTSConnection()
        ctxa = ProfileExecution(p, ExecutionDirection('s'),
                                Options(p.supported_options), c)
        a = ctxa.executor
        ctxb = ProfileExecution(p, ExecutionDirection('r'),
                                Options(p.supported_options), c)
        b = ctxb.executor

        a.send_msg('LALA')
        msg = b.wait_msg_type('LALA')
        self.assertEqual(msg.type, '__profid_LALA')
        self.assertEqual(msg.params, {})

        a.send_msg('LALA2')
        with self.assertRaises(ProtocolError):
            msg = b.wait_msg_type('LALA')
Exemplo n.º 8
0
    def test_finished(self):
        c = NullNSTSConnection()
        p = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB)
        opt = Options(p.supported_options)
        ctx = ProfileExecution(p, ExecutionDirection('s'), opt, c)
        time.sleep(0.8)
        ctx.mark_finished()

        passed = ctx.execution_time()
        self.assertTrue(abs(passed.raw_value - 0.8) < 0.1)
Exemplo n.º 9
0
    def test_properties(self):
        c = NullNSTSConnection()
        p = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB)
        dir = ExecutionDirection('s')
        opt = Options(p.supported_options)
        ctx = ProfileExecution(p, dir, opt, c)

        self.assertEqual(ctx.profile, p)
        self.assertEqual(ctx.connection, c)
        self.assertEqual(ctx.direction, dir)
        self.assertEqual(ctx.options, opt)
Exemplo n.º 10
0
    def test_propage_results(self):
        p = Profile('profid', 'profname', ProfileExecutorA, ProfileExecutorB)
        p.add_result('testdt', 'name', units.Time)
        p.add_result('testbit', 'name', units.BitRate)

        c = NullNSTSConnection()
        ctxa = ProfileExecution(p, ExecutionDirection('s'),
                                Options(p.supported_options), c)
        a = ctxa.executor
        ctxb = ProfileExecution(p, ExecutionDirection('r'),
                                Options(p.supported_options), c)
        b = ctxb.executor

        a.store_result('testdt', '10 sec')
        a.store_result('testbit', '32 bps')
        a.propagate_results()

        b.collect_results()
        self.assertEqual(b.results['testdt'], units.Time('10 sec'))
        self.assertEqual(b.results['testbit'], units.BitRate('32 bps'))
Exemplo n.º 11
0
    def test_executor(self):
        c = NullNSTSConnection()
        p = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB)
        opt = Options(p.supported_options)
        ctx = ProfileExecution(p, ExecutionDirection('s'), opt, c)

        x = ctx.executor
        self.assertIsInstance(x, ProfileExecutorA)
        self.assertEqual(x.profile, p)

        ctx = ProfileExecution(p, ExecutionDirection('r'), opt, c)
        x = ctx.executor
        self.assertIsInstance(x, ProfileExecutorB)
        self.assertEqual(x.profile, p)
Exemplo n.º 12
0
    def test_constructor_initializing(self):

        with self.assertRaises(TypeError):
            o = Options()

        d = OptionsDescriptor()
        d.add_option('test1', '', float)
        d.add_option('test2', '', float)
        o = Options(d, {'test1': '1.2'})
        self.assertLength(o, 2)

        with self.assertRaises(UnknownOptionError):
            o['unknown']
        self.assertEqual(o['test1'], 1.2)
        self.assertIsNone(o['test2'])

        # Initialize with unknown options
        with self.assertRaises(UnknownOptionError):
            o = Options(d, {'unknown': 0})

        # Initialize with wrong type
        with self.assertRaises(TypeError):
            o = Options(d, [])
Exemplo n.º 13
0
    def test_access(self):
        d = OptionsDescriptor()
        d.add_option('test', 'Hello', float)
        d.add_option('test2', 'Yeah', units.Time, 0)
        o = Options(d)

        with self.assertRaises(UnknownOptionError):
            o['unknown']

        # get item access
        self.assertIsNone(o['test'])
        self.assertEqual(o['test2'], units.Time(0))

        # Iterator access
        optids = []
        values = []
        for opt_id in o:
            optids.append(opt_id)
            values.append(o[opt_id])
        self.assertEqual(optids, ['test', 'test2'])
        self.assertEqual(values, [None, units.Time(0)])
Exemplo n.º 14
0
 def dummy_ctx(self):
     p = Profile('profid', 'profame', ProfileExecutor, ProfileExecutor)
     c = NullNSTSConnection()
     ctx = ProfileExecution(p, ExecutionDirection('s'),
                            Options(p.supported_options), c)
     return ctx
Exemplo n.º 15
0
 def __init__(self):
     self.tests = []
     self.__options = Options(SpeedTestOptionsDescriptor())
Exemplo n.º 16
0
 def __init__(self):
     self.__supported_options = ClientTerminalOptionsDescriptor()
     self.__options = Options(self.__supported_options)