Skip to content

Commit

Permalink
gw: make TestTemplate check all three options
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphlange committed Jan 19, 2024
1 parent 0534e68 commit ddb5819
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/p4p/test/test_gw.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,28 @@ def test_config(self):
content = F.read()
self.assertRegex(content, '"statusprefix"')

def test_systemd(self):
with NamedTemporaryFile() as F:
def test_systemd_instance(self):
with NamedTemporaryFile(suffix='@blah.service') as F:
try:
main(['--example-systemd', F.name])
except SystemExit as e:
self.assertEqual(e.code, 0)

F.seek(0)
content = F.read()
self.assertRegex(content, '-m p4p.gw /etc/pvagw/blah.conf')
self.assertRegex(content, 'multi-user.target')

def test_systemd_template(self):
with NamedTemporaryFile(suffix='@.service') as F:
try:
main(['--example-systemd', F.name])
except SystemExit as e:
self.assertEqual(e.code, 0)

F.seek(0)
content = F.read()
self.assertRegex(content, '-m p4p.gw /etc/pvagw/%i.conf')
self.assertRegex(content, 'multi-user.target')

class TestGC(RefTestCase):
Expand Down
2 changes: 1 addition & 1 deletion src/p4p/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class RegularNamedTemporaryFile(object):
"""Like tempfile.NamedTemporaryFile which doesn't use O_TEMPORARY on windows
"""
def __init__(self, *args, **kws):
fd, self.name = tempfile.mkstemp()
fd, self.name = tempfile.mkstemp(**kws)
try:
self.file = os.fdopen(fd, *args, **kws)
self.read = self.file.read
Expand Down

0 comments on commit ddb5819

Please sign in to comment.