import os
import sys
import unittest
import subprocess

class TestLightning(unittest.TestCase):

    @staticmethod
    def run_shell(args, timeout=30):
        process = subprocess.Popen(['electrum/tests/regtest/regtest.sh'] + args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
        for line in iter(process.stdout.readline, b''):
            sys.stdout.write(line.decode(sys.stdout.encoding))
        process.wait(timeout=timeout)
        process.stdout.close()
        assert process.returncode == 0

    def setUp(self):
        self.run_shell(['stop'])
        self.run_shell(['init'])
        self.run_shell(['start'])

    def tearDown(self):
        self.run_shell(['stop'])

    def test_breach(self):
        self.run_shell(['breach'])

    def test_forwarding(self):
        self.run_shell(['open'])
        self.run_shell(['alice_pays_carol'])
        self.run_shell(['close'])

    def test_redeem_htlcs(self):
        self.run_shell(['redeem_htlcs'])

    def test_breach_with_unspent_htlc(self):
        self.run_shell(['breach_with_unspent_htlc'])

    def test_breach_with_spent_htlc(self):
        self.run_shell(['breach_with_spent_htlc'])

    def test_watchtower(self):
        self.run_shell(['watchtower'])

@@ -529,41 +529,8 @@
 f):%0A
-        self.run_shell(%5B'stop'%5D)%0A
     

remove redundant 'stop' in regtest setUp (should run a bit faster)