Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilities/Zeroconf.app: Use dns-sd instead of avahi-browse #57

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Utilities/Zeroconf.app/Resources/CommandReader_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import unittest
from zeroconf import CommandReader
from PyQt5.QtCore import QObject, QProcess

class TestCommandReader(unittest.TestCase):
def setUp(self):
self.lines = []
self.return_code = None
self.parent = QObject()

def test_echo1(self):
cmd = CommandReader(self.parent, "echo", ["foo"])
output = []
cmd.lines.connect(output.append)
cmd.start()
cmd.wait()
self.assertEqual(output, [b"foo\n"])

def test_echo2(self):
cmd = CommandReader(self.parent, "echo", ["foo\nbar"])
output = []
cmd.lines.connect(output.append)
cmd.start()
cmd.wait()
self.assertEqual(output, [b"foo\n", b"bar\n"])

def test_echo_sleep1(self):
cmd = CommandReader(self.parent, "sh", ["-c", "echo foo && sleep 1 && echo bar"])
output = []
cmd.lines.connect(output.append)
cmd.start()
cmd.wait()
self.assertEqual(output, [b"foo\n", b"bar\n"])

def test_echo_sleep_false1(self):
cmd = CommandReader(self.parent, "sh", ["-c", "echo foo && sleep 1 && echo bar && false"])
output = []
cmd.lines.connect(output.append)
cmd.start()
cmd.wait()
self.assertEqual(output, [b"foo\n", b"bar\n"])

def test_kill1(self):
cmd = CommandReader(self.parent, "sh", ["-c", "echo foo && sleep 1 && echo bar"])
def handler(line):
self.assertEqual(line, b"foo\n")
cmd.kill()
cmd.lines.connect(handler)
cmd.start()
cmd.wait()
self.assertEqual(cmd.process.state(), QProcess.ProcessState.NotRunning)

if __name__ == "__main__":
unittest.main()
21 changes: 21 additions & 0 deletions Utilities/Zeroconf.app/Resources/ZeroconfService_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import unittest
from zeroconf import ZeroconfService

class TestCommandReader(unittest.TestCase):
def test_1(self):
service = ZeroconfService("foo server", "_http._tcp", "foo.local", "80")

self.assertEqual(service.name, "foo server")
self.assertEqual(service.service_type, "_http._tcp")
self.assertEqual(service.hostname_with_domain, "foo.local")
self.assertEqual(service.port, "80")
self.assertEqual(service.url, "http://foo.local:80")
self.assertEqual(service.__repr__(), "_http._tcp on foo.local:80")

def test_equality(self):
service1 = ZeroconfService("foo server", "_http._tcp", "foo.local", "80")
service2 = ZeroconfService("foo server2", "_http._tcp2", "foo.local", "80")
self.assertEqual(service1, service2)

if __name__ == "__main__":
unittest.main()
Loading