568
569
('_import', 'submodb5'),
569
570
('import', submodb_path, []),
574
class TestConvertImportToList(TestCase):
575
"""Directly test the conversion from import strings to lists"""
577
def check_result(self, expected, import_strings):
579
for import_str in import_strings:
580
lazy_import._convert_import_str_to_map(import_str, imports)
581
self.assertEqual(expected, imports,
582
'Import of %r was not converted correctly'
583
' %s != %s' % (import_strings, expected, imports))
585
def test_import_one(self):
586
self.check_result({'one':(['one'], None, {}),
589
def test_import_one_two(self):
590
one_two_map = {'one':(['one'], None,
591
{'two':(['one', 'two'], None, {}),
594
self.check_result(one_two_map, ['import one.two'])
595
self.check_result(one_two_map, ['import one, one.two'])
596
self.check_result(one_two_map, ['import one', 'import one.two'])
597
self.check_result(one_two_map, ['import one.two', 'import one'])
599
def test_import_one_two_three(self):
600
one_two_three_map = {
601
'one':(['one'], None,
602
{'two':(['one', 'two'], None,
603
{'three':(['one', 'two', 'three'], None, {}),
607
self.check_result(one_two_three_map, ['import one.two.three'])
608
self.check_result(one_two_three_map, ['import one, one.two.three'])
609
self.check_result(one_two_three_map, ['import one',
610
'import one.two.three'])
611
self.check_result(one_two_three_map, ['import one.two.three',
614
def test_import_one_as_x(self):
615
self.check_result({'x':(['one'], None, {}),
616
}, ['import one as x'])
618
def test_import_one_two_as_x(self):
619
self.check_result({'x':(['one', 'two'], None, {}),
620
}, ['import one.two as x'])
622
def test_import_mixed(self):
623
mixed = {'x':(['one', 'two'], None, {}),
624
'one':(['one'], None,
625
{'two':(['one', 'two'], None, {}),
628
self.check_result(mixed, ['import one.two as x, one.two'])
629
self.check_result(mixed, ['import one.two as x', 'import one.two'])
630
self.check_result(mixed, ['import one.two', 'import one.two as x'])
632
def test_import_with_as(self):
633
self.check_result({'fast':(['fast'], None, {})}, ['import fast'])
635
# These will be used when we want to check converting 'import foo' into
636
# the parameters necessary for creating ImportReplacer objects
637
# def check_result(self, expected, import_string):
638
# val = lazy_import._convert_import_to_list(import_string)
639
# self.assertEqual(expected, val)
641
# def test_import_one(self):
642
# self.check_result(['one', ['one'], None, []], 'import one')
644
# def test_import_one_two(self):
645
# self.check_result(['one', ['one'], None,
646
# [('two', ['one', 'two'], [])]
650
# def test_import_one_two_three(self):
651
# self.check_result(['one', ['one'], None,
652
# [('two', ['one', 'two'],
653
# [('three', ['one', 'two', 'three'], []),
658
# 'import one.two.three')
660
# def test_from_one_import_two(self):
661
# self.check_result(['two', ['one'], 'two', []], 'from one import two')
663
# def test_from_one_two_import_three(self):
664
# self.check_result(['three', ['one', 'two'], 'three', []],
665
# 'from one.two import three')