[Python-checkins] r55988 - sandbox/trunk/pep0/test_pep0.py

brett.cannon python-checkins at python.org
Fri Jun 15 05:42:52 CEST 2007


Author: brett.cannon
Date: Fri Jun 15 05:42:49 2007
New Revision: 55988

Removed:
   sandbox/trunk/pep0/test_pep0.py
Log:
Ditch test file.  Just easier to run on actual PEPs.


Deleted: /sandbox/trunk/pep0/test_pep0.py
==============================================================================
--- /sandbox/trunk/pep0/test_pep0.py	Fri Jun 15 05:42:49 2007
+++ (empty file)
@@ -1,313 +0,0 @@
-from __future__ import with_statement
-import pep0.parse
-
-import itertools
-import unittest
-from test import test_support
-from contextlib import contextmanager
-import os
-
-class ParseTests(unittest.TestCase):
-
-    """Test pep0.parse ."""
-
-    def create_path(self):
-        return test_support.TESTFN + str(self.num)
-
-    def setUp(self):
-        self.num = 42
-        self.path = self.create_path()
-
-    def tearDown(self):
-        if os.path.exists(self.path):
-            os.unlink(self.path)
-
-    def create_simple_pep(self, num=None):
-        if num is None:
-            num = self.num
-        with open(self.path, 'w') as pep_file:
-            pep_file.write("PEP: %s\n\nBody" % num)
-
-    def test_split_metadata_single_line(self):
-        # Test basic use case.
-        gave_field = "field"
-        gave_data = "data"
-        # Spaces in separator help test whitespace stripping.
-        for sep in (':', ' :', ': '):
-            line = sep.join([gave_field, gave_data])
-            got_field, got_data = pep0.parse.split_metadata(line)
-            self.failUnlessEqual(gave_field, got_field)
-            self.failUnlessEqual(gave_data, got_data)
-        bad_line = 'abc'
-        self.failUnlessRaises(ValueError, pep0.parse.split_metadata, bad_line)
-
-    def test_split_metadata_continuing_line(self):
-        # Make sure that if the line is considered a continuation of another
-        # one that the same field is returned.
-        gave_field ='a'
-        gave_data = 'b:c'
-        got_field, got_data = pep0.parse.split_metadata(gave_data, gave_field)
-        self.failUnlessEqual(got_field, gave_field)
-        self.failUnlessEqual(got_data, gave_data)
-
-    def test_consume_pep_number_field(self):
-        # All PEPs must have a PEP field.
-        self.create_simple_pep()
-        metadata = pep0.parse.consume_pep(self.path)
-        self.failUnless('PEP' in metadata)
-        self.failUnlessEqual(metadata['PEP'], self.num)
-
-    def test_consume_pep_file_name(self):
-        # The PEP number is expected to be in file name.
-        # Testing positive results implicit in other tests of pep0.consume_pep.
-        self.path = test_support.TESTFN
-        assert str(self.num) not in self.path
-        self.create_simple_pep()
-        self.failUnlessRaises(ValueError, pep0.parse.consume_pep, self.path)
-
-    def test_consume_pep_valid_int(self):
-        # The found value of the 'PEP' field is expected to be a valid number.
-        self.create_simple_pep("XXX")
-        self.failUnlessRaises(ValueError, pep0.parse.consume_pep, self.path)
-
-    def test_consume_pep_multiline_data(self):
-        # If data spans multiple lines it should come out as a single one after
-        # parsing.
-        line1 = "a, b, c,"
-        line2 = "d, e, f"
-        with open(self.path, 'w') as pep_file:
-            pep_file.write("PEP: %s\n" % self.num)
-            pep_file.write("multiline: a, b, c,\n")
-            pep_file.write(" d, e, f\n")
-            pep_file.write("\nBody")
-        metadata = pep0.parse.consume_pep(self.path)
-        self.failUnlessEqual(metadata['multiline'], line1 + line2)
-
-
-class HandlerTests(unittest.TestCase):
-
-    """Test the PEP field handlers for parsing data."""
-
-    def test_handle_generic(self):
-        # Identity function.
-        for data in ('spam', 'spam,', '', 'spam, monty'):
-            self.failUnlessEqual(pep0.handle_generic(data), data)
-
-    def test_pep_num(self):
-        # String -> int.
-        num = 42
-        string_rep = str(num)
-        self.failUnlessEqual(pep0.handle_pep_num(string_rep), num)
-
-    def test_handle_csv(self):
-        # Split on commas.
-        data = ['a', 'b', 'c']
-        string_rep = ','.join(data)
-        self.failUnlessEqual(pep0.handle_csv(string_rep), data)
-        string_rep = ', '.join(data)
-        self.failUnlessEqual(pep0.handle_csv(string_rep), data)
-        string_rep = ', '.join(data) + ','
-        got = pep0.handle_csv(string_rep)
-        self.failUnlessEqual(got, data,
-                             '%r != %r (using %r)' %
-                             (got, data, string_rep))
-
-    def test_handle_author(self):
-        # Handle the various ways authors can be specified.
-        # Test needs to validate not just how the author's name can be written
-        # but also variations in people's names (e.g., 'van', 'Jr.', etc.).
-        authors = ["Guido van Rossum", "Brett Cannon", "Fred L. Drake, Jr.",
-                    "Aahz"]
-        formats = ["%s <email>", "email (%s)", "%s"]
-        for format in formats:
-            for author_count in range(len(authors)):
-                rep = ', '.join(format % author
-                                    for author in authors[:author_count+1])
-                expect = authors[:author_count+1]
-                got = pep0.handle_author(rep)
-                self.failUnlessEqual(got, expect)
-                # Test with a trailing comma.
-                rep += ','
-                got = pep0.handle_author(rep)
-                self.failUnlessEqual(got, expect)
-
-
-class PEPClassTests(unittest.TestCase):
-
-    """Test the PEP class."""
-
-    def setUp(self):
-        self.metadata = {'PEP': 42, 'Type': pep0.pep.PEP.type_values[0],
-                            'Status': pep0.pep.PEP.status_values[0],
-                            'Author': "Brett Cannon"}
-
-    def test_init_number(self):
-        # PEP number must be an int.
-        pep = pep0.pep.PEP(self.metadata)
-        self.failUnlessEqual(pep.number, self.metadata['PEP'])
-        self.metadata['PEP'] = 'XXX'
-        self.failUnlessRaises(ValueError, pep0.pep.PEP, self.metadata)
-
-    def test_init_status(self):
-        # Invalid Status entry raises an exception.
-        pass
-
-    def test_init_type(self):
-        # Invalid type should raise an exception.
-        pass
-
-    def test_init_authors(self):
-        # There should be at least one author.
-        pass
-
-
- at contextmanager
-def test_file(path):
-    try:
-        open_file = open(path, 'w')
-        yield open_file
-    finally:
-        open_file.close()
-        if os.path.exists(path):
-            os.unlink(path)
-
-
-class ConsumePepTests(unittest.TestCase):
-
-    """Test the reading and parsing of a PEP file."""
-
-    def test_single_line(self):
-        # Test a PEP that only has a single line of metadata.
-        type_ = 'Spam'
-        data = 'Monty'
-        with test_file(test_support.TESTFN) as pep_file:
-            pep_file.write('%s: %s\n' % (type_, data))
-            pep_file.write('\n')
-            pep_file.write('The PEP.')
-            pep_file.close()
-            metadata = pep0.consume_pep(test_support.TESTFN)
-            self.failUnless(type_ in metadata)
-            self.failUnlessEqual(metadata[type_], data)
-
-    def test_multi_line_authors(self):
-        # Make sure that metadata that takes multiple lines works when it
-        # is expected (e.g., Author and Post-History).
-        authors = ['A', 'B']
-        output = 'Author: ' + authors[0] + '\n'
-        output += '   ' + authors[1] + '\n'
-        with test_file(test_support.TESTFN) as pep_file:
-            pep_file.write(output)
-            pep_file.write('\n')
-            pep_file.write('The PEP.')
-            pep_file.close()
-            metadata = pep0.consume_pep(test_support.TESTFN)
-            self.failUnless('Author' in metadata)
-            self.failUnlessEqual(metadata['Author'], authors)
-
-    def test_multi_line_post_history(self):
-        # Post-History entries on multiple lines is fine.
-        dates = ['04-Jul-1776', '23-Oct-2007', '01-Jan-2001']
-        output = 'Post-History: ' + ', '.join(dates[:2]) + '\n'
-        output += '    ' + dates[2] + '\n'
-        with test_file(test_support.TESTFN) as pep_file:
-            pep_file.write(output)
-            pep_file.write('\n')
-            pep_file.write('The PEP.')
-            pep_file.close()
-            metadata = pep0.consume_pep(test_support.TESTFN)
-            self.failUnless('Post-History' in metadata)
-            self.failUnlessEqual(metadata['Post-History'], dates)
-
-    def test_missing_fields(self):
-        # Missing key fields should raise ValueError.
-        # PEP
-        # Author
-        # Type
-        # Status
-        pass
-
-    def test_pep_field(self):
-        # PEP field should only contain a number.
-        pass
-
-    def test_author_field(self):
-        # Author field should have at least a single author.
-        pass
-
-    def test_type_field(self):
-        # Type field should contain only a valid value.
-        pass
-
-    def test_status_field(self):
-        # Status field should contain only a valid value.
-        pass
-
-
-class EntryOutputTests(unittest.TestCase):
-
-    """Tests for single-line output into the index."""
-
-    def test_make_entry_type(self):
-        # Test handling of type_ argument.
-        pass
-
-    def test_make_entry_status(self):
-        # make_entry's status argument.
-        pass
-
-    def test_make_entry_number(self):
-        # make_entry's number argument.
-        pass
-
-    def test_make_entry_number(self):
-        # make_entry's title argument.
-        pass
-
-    def test_make_entry_title(self):
-        # make_entry's title argument.
-        pass
-
-    def test_make_entry_owners(self):
-        # make_entry's owners argument.
-        pass
-
-    def test_make_entry_column_headers(self):
-        # Should be able to output column headers properly.
-        pass
-
-    def test_make_entry_underline(self):
-        # Underlining of column headers should be okay.
-        pass
-
-    def test_author_last_name(self):
-        # Test that last names are discovered properly.
-        test_names = [("Brett Cannon", "Cannon"),
-                        ("Guido van Rossum", "van Rossum"),
-                        ("Fred L. Drake, Jr.", "Drake"),
-                        ("Aahz", "Aahz"),
-                     ]
-        for full_name, expect in test_names:
-            got = pep0.last_name(full_name)
-            self.failUnlessEqual(got, expect)
-
-    def test_author_nickname(self):
-        # Make sure nicknames are returned instead of last names when a
-        # nickname is available.
-        full_name = 'Guido van Rossum'
-        nickname = 'GvR'
-        last_name = 'van Rossum'
-        got = pep0.last_name(full_name, {full_name:nickname})
-        self.failUnlessEqual(got, nickname)
-        got = pep0.last_name(full_name, {'asdf':nickname})
-        self.failUnlessEqual(got, last_name)
-
-
-def test_main():
-    test_support.run_unittest(
-                ParseTests,
-                PEPClassTests,
-            )
-
-
-if __name__ == '__main__':
-    test_main()


More information about the Python-checkins mailing list