~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-11 22:55:35 UTC
  • mto: This revision was merged to the branch mainline in revision 2004.
  • Revision ID: john@arbash-meinel.com-20060911225535-b20aae01acc390b8
small test updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
574
574
class TestConvertImportToMap(TestCase):
575
575
    """Directly test the conversion from import strings to maps"""
576
576
 
577
 
    def check_result(self, expected, import_strings):
 
577
    def check(self, expected, import_strings):
578
578
        proc = lazy_import.ImportProcessor()
579
579
        for import_str in import_strings:
580
580
            proc._convert_import_str(import_str)
584
584
                                        proc.imports))
585
585
 
586
586
    def test_import_one(self):
587
 
        self.check_result({'one':(['one'], None, {}),
588
 
                          }, ['import one'])
 
587
        self.check({'one':(['one'], None, {}),
 
588
                   }, ['import one'])
589
589
 
590
590
    def test_import_one_two(self):
591
591
        one_two_map = {'one':(['one'], None,
592
592
                              {'two':(['one', 'two'], None, {}),
593
593
                              }),
594
594
                      }
595
 
        self.check_result(one_two_map, ['import one.two'])
596
 
        self.check_result(one_two_map, ['import one, one.two'])
597
 
        self.check_result(one_two_map, ['import one', 'import one.two'])
598
 
        self.check_result(one_two_map, ['import one.two', 'import one'])
 
595
        self.check(one_two_map, ['import one.two'])
 
596
        self.check(one_two_map, ['import one, one.two'])
 
597
        self.check(one_two_map, ['import one', 'import one.two'])
 
598
        self.check(one_two_map, ['import one.two', 'import one'])
599
599
 
600
600
    def test_import_one_two_three(self):
601
601
        one_two_three_map = {
605
605
                           }),
606
606
                   }),
607
607
        }
608
 
        self.check_result(one_two_three_map, ['import one.two.three'])
609
 
        self.check_result(one_two_three_map, ['import one, one.two.three'])
610
 
        self.check_result(one_two_three_map, ['import one',
 
608
        self.check(one_two_three_map, ['import one.two.three'])
 
609
        self.check(one_two_three_map, ['import one, one.two.three'])
 
610
        self.check(one_two_three_map, ['import one',
611
611
                                              'import one.two.three'])
612
 
        self.check_result(one_two_three_map, ['import one.two.three',
 
612
        self.check(one_two_three_map, ['import one.two.three',
613
613
                                              'import one'])
614
614
 
615
615
    def test_import_one_as_x(self):
616
 
        self.check_result({'x':(['one'], None, {}),
 
616
        self.check({'x':(['one'], None, {}),
617
617
                          }, ['import one as x'])
618
618
 
619
619
    def test_import_one_two_as_x(self):
620
 
        self.check_result({'x':(['one', 'two'], None, {}),
621
 
                          }, ['import one.two as x'])
 
620
        self.check({'x':(['one', 'two'], None, {}),
 
621
                   }, ['import one.two as x'])
622
622
 
623
623
    def test_import_mixed(self):
624
624
        mixed = {'x':(['one', 'two'], None, {}),
626
626
                       {'two':(['one', 'two'], None, {}),
627
627
                       }),
628
628
                }
629
 
        self.check_result(mixed, ['import one.two as x, one.two'])
630
 
        self.check_result(mixed, ['import one.two as x', 'import one.two'])
631
 
        self.check_result(mixed, ['import one.two', 'import one.two as x'])
 
629
        self.check(mixed, ['import one.two as x, one.two'])
 
630
        self.check(mixed, ['import one.two as x', 'import one.two'])
 
631
        self.check(mixed, ['import one.two', 'import one.two as x'])
632
632
 
633
633
    def test_import_with_as(self):
634
 
        self.check_result({'fast':(['fast'], None, {})}, ['import fast'])
 
634
        self.check({'fast':(['fast'], None, {})}, ['import fast'])
635
635
 
636
636
 
637
637
class TestFromToMap(TestCase):
704
704
        self.check(['from one import two'], '\nfrom one import two\n\n')
705
705
        self.check(['from one import two'], '\nfrom one import (two)\n')
706
706
        self.check(['from one import  two '], '\nfrom one import (\n\ttwo\n)\n')
 
707
 
 
708
    def test_multiple(self):
 
709
        self.check(['import one', 'import two, three', 'from one import four'],
 
710
                   'import one\nimport two, three\nfrom one import four')
 
711
        self.check(['import one', 'import two, three', 'from one import four'],
 
712
                   'import one\nimport (two, three)\nfrom one import four')
 
713
        self.check(['import one', 'import  two, three', 'from one import four'],
 
714
                   'import one\n'
 
715
                   'import (\n'
 
716
                   'two, three)\n'
 
717
                   'from one import four')
 
718
        self.check(['import  one, ',
 
719
                    'import  two, three, ', 'from one import  four, '],
 
720
                   'import (\n'
 
721
                   '    one,\n'
 
722
                   '    )\n'
 
723
                   'import (\n'
 
724
                   '    two,\n'
 
725
                   '    three,\n'
 
726
                   '    )\n'
 
727
                   'from one import (\n'
 
728
                   '    four,\n'
 
729
                   '    )\n'
 
730
                   )