本文整理汇总了Python中gstswitch.server.Server类的典型用法代码示例。如果您正苦于以下问题:Python Server类的具体用法?Python Server怎么用?Python Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_encode_port
def get_encode_port(num):
"""Test get_encode_port - num times"""
video_port = 3000
serv = Server(path=PATH, video_port=video_port)
try:
serv.run()
sources = TestSources(video_port=video_port)
sources.new_test_video()
expected_res = [video_port + 2] * num
controller = Controller()
controller.establish_connection()
res = []
for _ in range(num):
res.append(controller.get_encode_port())
assert expected_res == res
finally:
if serv.proc:
poll = serv.proc.poll()
if poll == -11:
print "SEGMENTATION FAULT OCCURRED"
print "ERROR CODE - {0}".format(poll)
serv.terminate(1)
log = open('server.log')
print log.read()
示例2: main
def main(args):
print("running server")
serv = Server(path=args.path)
serv.run()
wait(5)
print("running source pattern=1")
sources = TestSources(video_port=3000, audio_port=4000)
sources.new_test_video(pattern=1)
wait(5)
print("running gst-switch-ui")
# the & will run this in the background so control returns
# and we can bring up the 2nd source
call("gst-switch-ui &", shell=True)
wait(5)
print("running source pattern=18")
sources.new_test_video(pattern=18)
raw_input("hit enter:")
# need to kill off the processes.
# a better wy of doing is would be to use
# https://docs.python.org/2/library/subprocess.html#subprocess.Popen.kill
# but I don't feel like figuring it out :p
call("pkill gst-switch-ui", shell=True)
call("pkill gst-switch-srv", shell=True)
示例3: get_audio_port
def get_audio_port(num):
"""Test get_audio_port"""
audio_port = 8000
serv = Server(path=PATH, audio_port=audio_port)
try:
serv.run()
sources = TestSources(audio_port=audio_port)
sources.new_test_audio()
expected_res = [3003] * num
controller = Controller()
controller.establish_connection()
res = []
for _ in range(num):
res.append(controller.get_audio_port())
assert expected_res == res
finally:
if serv.proc:
poll = serv.proc.poll()
if poll == -11:
print("SEGMENTATION FAULT OCCURRED")
print("ERROR CODE - {0}".format(poll))
serv.terminate(1)
log = open('server.log')
print(log.read())
示例4: test_run_process
def test_run_process(self):
"""Test _run_process method"""
serv = Server(path='abc')
serv._start_process = Mock(return_value=MockProcess())
serv.gst_option_string = ''
ret = serv._run_process()
assert ret is not None
示例5: test_kill_fail
def test_kill_fail(self):
"""Test when kill fails"""
serv = Server(path=PATH)
serv.proc = 1
serv.pid = -300
with pytest.raises(ServerProcessError):
serv.kill()
示例6: permutate_adjust_pip
def permutate_adjust_pip(num, delay):
"""Adjust_pip num number of times"""
import random
video_port = 3000
serv = Server(path=PATH, video_port=video_port)
try:
serv.run()
sources = TestSources(video_port=video_port)
sources.new_test_video(pattern=6)
sources.new_test_video(pattern=5)
preview = PreviewSinks()
preview.run()
controller = Controller()
for _ in range(num):
xpos = random.randrange(-20, 20)
ypos = random.randrange(-20, 20)
res = controller.adjust_pip(xpos, ypos, 0, 0)
time.sleep(delay)
assert res is not None
preview.terminate()
sources.terminate_video()
finally:
if serv.proc:
poll = serv.proc.poll()
if poll == -11:
print "SEGMENTATION FAULT OCCURRED"
print "ERROR CODE - {0}".format(poll)
serv.terminate(1)
log = open('server.log')
print log.read()
示例7: get_preview_ports
def get_preview_ports(num):
"""Get Preview Ports when num number of sources are added"""
video_port = 3000
serv = Server(path=PATH, video_port=video_port)
try:
serv.run()
sources = TestSources(video_port=video_port)
expected_res = [ i for i in range(3003, 3003 + num)]
controller = Controller()
res = []
for _ in range(num):
sources.new_test_video()
controller.establish_connection()
res = controller.get_preview_ports()
print res
assert expected_res == res
finally:
if serv.proc:
poll = serv.proc.poll()
if poll == -11:
print "SEGMENTATION FAULT OCCURRED"
print "ERROR CODE - {0}".format(poll)
serv.terminate(1)
log = open('server.log')
print log.read()
示例8: test_run
def test_run(self):
"""Test the run method"""
serv = Server(path='abc')
serv._run_process = Mock(return_value=MockProcess())
serv.run()
assert serv.pid == 1
assert serv.proc is not None
示例9: main
def main(args):
print("running server")
serv = Server(path=args.path)
serv.run()
wait(5)
print("running source pattern=1")
sources = TestSources(video_port=3000, audio_port=4000)
sources.new_test_video(pattern=1)
wait(5)
print("running gst-switch-ui")
# the & will run this in the background so control returns
# and we can bring up the 2nd source
# Replaced call with subprocess.Popen.
SwitchUi = subprocess.Popen("gst-switch-ui &",shell=True)
wait(5)
print("running source pattern=18")
sources.new_test_video(pattern=18)
raw_input("hit enter:")
# Replaced pkill call with Popen.kill
subprocess.Popen.kill(SwitchUi)
serv.kill()
示例10: test_raises_oserror
def test_raises_oserror(self):
"""Test what happens when ProcessMonitor raises an OSError"""
with patch("gstswitch.server.ProcessMonitor") as mock:
mock.side_effect = OSError()
serv = Server(path="abc")
with pytest.raises(ServerProcessError):
serv._start_process("cmd")
示例11: test_kill
def test_kill(self, monkeypatch):
"""Test kill ServerProcessError"""
serv = Server(path='abc')
serv.proc = Mock()
monkeypatch.setattr(os, 'kill', Mock(side_effect=OSError))
with pytest.raises(ServerProcessError):
serv.kill()
示例12: test_gcov_flush_fail
def test_gcov_flush_fail(self):
"""Test when gcov_flush fails"""
serv = Server(path=PATH)
serv.proc = 1
serv.pid = -300
with pytest.raises(ServerProcessError):
serv.gcov_flush()
示例13: test_raises_enoent
def test_raises_enoent(self):
"""Test what happens when ProcessMonitor raises an OSError ENOENT"""
with patch("gstswitch.server.ProcessMonitor") as mock:
mock.side_effect = OSError(ENOENT, "not found")
serv = Server(path="abc")
with pytest.raises(PathError):
serv._start_process("cmd")
示例14: test_log_to_stderr
def test_log_to_stderr(self):
"""Test log_to_file=False property"""
with patch("gstswitch.server.ProcessMonitor") as mock:
serv = Server(path="abc")
serv.log_to_file = False
serv._start_process("cmd")
mock.assert_called_with("cmd")
示例15: test_start_process_error
def test_start_process_error(self, monkeypatch):
"""Test _start_process method"""
with patch("subprocess.Popen.__init__") as mock:
mock.side_effect = OSError
serv = Server(path="abc")
with pytest.raises(ServerProcessError):
serv._start_process("def")