Browse Source

clean up how we check that the process runs... This is better as it

allows to check output, and prevents spamming to test console.  It
also sets up the environment closer to a real run.
tags/v0.1.0
John-Mark Gurney 5 years ago
parent
commit
52460a3912
1 changed files with 29 additions and 12 deletions
  1. +29
    -12
      ntunnel.py

+ 29
- 12
ntunnel.py View File

@@ -316,21 +316,34 @@ class TestMain(unittest.TestCase):
shutil.rmtree(self.basetempdir)
self.tempdir = None

def test_noargs(self):
sys.argv = [ 'prog' ]
@async_test
async def test_noargs(self):
proc = await self.run_with_args()

with self.assertRaises(SystemExit) as cm:
main()
await proc.wait()

# XXX - not checking error message

# And that it exited w/ the correct code
self.assertEqual(5, cm.exception.code)
self.assertEqual(proc.returncode, 5)

def run_with_args(self, *args):
return asyncio.create_subprocess_exec(sys.executable,
__file__, *args,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE)

def test_genkey(self):
def test_both(self):
pass

@async_test
async def test_genkey(self):
# that it can generate a key
sys.argv = [ 'prog', 'genkey', 'somefile' ]
main()
proc = await self.run_with_args('genkey', 'somefile')

await proc.wait()

self.assertEqual(proc.returncode, 0)

with open('somefile.pub', encoding='ascii') as fp:
lines = fp.readlines()
@@ -347,13 +360,17 @@ class TestMain(unittest.TestCase):
self.assertIsInstance(key, x448.X448PrivateKey)

# that a second call fails
with self.assertRaises(SystemExit) as cm:
main()
proc = await self.run_with_args('genkey', 'somefile')

# XXX - not checking error message
await proc.wait()

stdoutdata, stderrdata = await proc.communicate()

self.assertFalse(stdoutdata)
self.assertEqual(b'failed to create somefile.pub, file exists.\n', stderrdata)

# And that it exited w/ the correct code
self.assertEqual(1, cm.exception.code)
self.assertEqual(proc.returncode, 1)

class TestNoiseFowarder(unittest.TestCase):
def setUp(self):


Loading…
Cancel
Save