~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lazy_import.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-12 18:42:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2004.
  • Revision ID: john@arbash-meinel.com-20060912184249-83efc58bcc327550
Add more structured error handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
784
784
                   '    )\n'
785
785
                   )
786
786
 
 
787
    def test_missing_trailing(self):
 
788
        proc = lazy_import.ImportProcessor()
 
789
        self.assertRaises(errors.InvalidImportLine,
 
790
                          proc._canonicalize_import_text,
 
791
                          "from foo import (\n  bar\n")
 
792
 
787
793
 
788
794
class TestImportProcessor(TestCase):
789
795
    """Test that ImportProcessor can turn import texts into lazy imports"""
877
883
                        'import one\n'
878
884
                        'import one.two\n')
879
885
 
 
886
    def test_incorrect_line(self):
 
887
        proc = lazy_import.ImportProcessor()
 
888
        self.assertRaises(errors.InvalidImportLine,
 
889
                          proc._build_map, 'foo bar baz')
 
890
        self.assertRaises(errors.InvalidImportLine,
 
891
                          proc._build_map, 'improt foo')
 
892
        self.assertRaises(errors.InvalidImportLine,
 
893
                          proc._build_map, 'importfoo')
 
894
        self.assertRaises(errors.InvalidImportLine,
 
895
                          proc._build_map, 'fromimport')
 
896
 
 
897
    def test_name_collision(self):
 
898
        proc = lazy_import.ImportProcessor()
 
899
        proc._build_map('import foo')
 
900
 
 
901
        # All of these would try to create an object with the
 
902
        # same name as an existing object.
 
903
        self.assertRaises(errors.ImportNameCollision,
 
904
                          proc._build_map, 'import bar as foo')
 
905
        self.assertRaises(errors.ImportNameCollision,
 
906
                          proc._build_map, 'from foo import bar as foo')
 
907
        self.assertRaises(errors.ImportNameCollision,
 
908
                          proc._build_map, 'from bar import foo')
 
909
 
880
910
 
881
911
class TestLazyImportProcessor(ImportReplacerHelper):
882
912