Ticket #5989: examples-react-5989-3.patch

File examples-react-5989-3.patch, 4.0 KB (added by Richard Wall, 7 years ago)

Update patch against source:branches/examples-react-5989

  • twisted/names/test/test_examples.py

    diff -r -u examples-react-5989/twisted/names/test/test_examples.py examples-react-5989-2/twisted/names/test/test_examples.py
    old new  
    22# See LICENSE for details.
    33
    44"""
    5 Tests for L{twisted.names.tap}.
     5Tests for L{twisted.names} example scripts.
    66"""
    7 import os
     7
    88import sys
    99from StringIO import StringIO
    1010
     
    4343        for childName in self.examplePath:
    4444            here = here.child(childName)
    4545        if not here.exists():
    46             raise SkipTest("Examples (%s) not found - cannot test" % (here.path,))
     46            raise SkipTest(
     47                "Examples (%s) not found - cannot test" % (here.path,))
    4748        sys.path.append(here.parent().path)
    4849        # Import the example as a module
    4950        moduleName = here.basename().split('.')[0]
     
    5354
    5455    def tearDown(self):
    5556        """
    56         Remove the example directory from the path and remove all modules loaded by
    57         the test from sys.modules.
     57        Remove the example directory from the path and remove all
     58        modules loaded by the test from sys.modules.
    5859        """
    5960        sys.modules.clear()
    6061        sys.modules.update(self.originalModules)
     
    6263        sys.stderr = self.originalErr
    6364
    6465
    65     def test_executable(self):
     66    def test_shebang(self):
    6667        """
    67         The example scripts should start with the standard shebang
    68         line and should be executable.
     68        The example scripts start with the standard shebang line.
    6969        """
    7070        self.assertEquals(
    7171            self.examplePath.open().readline().rstrip(),
    7272            '#!/usr/bin/env python')
    7373
    74         mode = oct(os.stat(self.examplePath.path).st_mode)[-3:]
    75         self.assertEquals(
    76             mode, '775',
    77             'Wrong permissions. %r on %r' % (mode, self.examplePath.path))
    78 
    7974
    80     def test_usage(self):
     75    def test_usageConsistency(self):
    8176        """
    82         The example script prints a usage message to stderr and raises
    83         SystemExit if it is passed incorrect command line
    84         arguments. The first line should contain a USAGE summary and
    85         the last line should contain an ERROR, explaining that
     77        The example script prints a usage message to stderr if it is
     78        passed unrecognised command line arguments.
     79
     80        The first line should contain a USAGE summary, explaining the
     81        accepted command arguments.
     82
     83        The last line should contain an ERROR summary, explaining that
    8684        incorrect arguments were supplied.
    8785        """
    8886        self.assertRaises(SystemExit, self.example.main, None)
    8987        err = self.fakeErr.getvalue().splitlines()
    90         self.assertEquals(err[0][:len('USAGE:')], 'USAGE:')
    91         self.assertEquals(err[-1][:len('ERROR:')], 'ERROR:')
     88        self.assertTrue(
     89            err[0].startswith('USAGE:'),
     90            'Usage message first line should start with "USAGE:". '
     91            'Actual: %r' % (err[0],))
     92        self.assertTrue(
     93            err[-1].startswith('ERROR:'),
     94            'Usage message last line should start with "ERROR:" '
     95            'Actual: %r' % (err[-1],))
     96
    9297
    9398
    9499class TestDnsTests(ExampleTestBase, TestCase):
    95100    """
    96     Tests for the testdns.py example script.
     101    Test the testdns.py example script.
    97102    """
    98103
    99104    examplePath = 'doc/names/examples/testdns.py'.split('/')
     
    101106
    102107class GetHostByNameTests(ExampleTestBase, TestCase):
    103108    """
    104     Tests for the gethostbyname.py example script.
     109    Test the gethostbyname.py example script.
    105110    """
    106111
    107112    examplePath = 'doc/names/examples/gethostbyname.py'.split('/')
     
    109114
    110115class DnsServiceTests(ExampleTestBase, TestCase):
    111116    """
    112     Tests for the dns-service.py example script.
     117    Test the dns-service.py example script.
    113118    """
    114119
    115120    examplePath = 'doc/names/examples/dns-service.py'.split('/')