示例#1
0
 def test_should_add_imports_with_no_prior_imports(self):
     filename = self.create_file("foo.py", "obj = json.dumps(23)")
     (change, ) = autoimport.get_changes(filename)
     self.assertEqual(change['action'], 'change')
     self.assertEqual(change['file'], filename)
     self.assertEqual(change['contents'], "import json\n"
                      "obj = json.dumps(23)")
示例#2
0
 def test_should_add_imports_with_no_prior_imports(self):
     filename = self.create_file("foo.py",
                                 "conf = ConfigParser.SafeConfigParser()")
     (change,) = autoimport.get_changes(filename)
     self.assertEqual(change['action'], 'change')
     self.assertEqual(change['file'], filename)
     self.assertEqual(change['contents'],
                      "import ConfigParser\n"
                      "conf = ConfigParser.SafeConfigParser()")
示例#3
0
 def test_should_add_imports_with_no_prior_imports(self):
     filename = self.create_file("foo.py",
                                 "obj = json.dumps(23)")
     (change,) = autoimport.get_changes(filename)
     self.assertEqual(change['action'], 'change')
     self.assertEqual(change['file'], filename)
     self.assertEqual(change['contents'],
                      "import json\n"
                      "obj = json.dumps(23)")
示例#4
0
 def test_should_not_add_duplicates(self):
     filename = self.create_file(
         "foo.py", "if sys.argv[1]:\n"
         "    sys.exit('yiakes')\n")
     (change, ) = autoimport.get_changes(filename)
     self.assertEqual(change['action'], 'change')
     self.assertEqual(change['file'], filename)
     self.assertEqual(
         change['contents'], "import sys\n"
         "if sys.argv[1]:\n"
         "    sys.exit('yiakes')\n")
示例#5
0
 def test_should_not_add_duplicates(self):
     filename = self.create_file("foo.py",
                                 "if sys.argv[1]:\n"
                                 "    sys.exit('yiakes')\n")
     (change,) = autoimport.get_changes(filename)
     self.assertEqual(change['action'], 'change')
     self.assertEqual(change['file'], filename)
     self.assertEqual(change['contents'],
                      "import sys\n"
                      "if sys.argv[1]:\n"
                      "    sys.exit('yiakes')\n")
示例#6
0
 def test_should_do_nothing_for_global_names(self):
     filename = self.create_file("foo.py", "open('foo').read()")
     self.assertEqual(autoimport.get_changes(filename), [])
示例#7
0
文件: refactor.py 项目: 0sn/elpy
 def refactor_add_missing_imports(self):
     return autoimport.get_changes(self.resource.real_path)
示例#8
0
 def test_should_do_nothing_for_global_names(self):
     filename = self.create_file("foo.py",
                                 "open('foo').read()")
     self.assertEqual(autoimport.get_changes(filename),
                      [])
示例#9
0
 def refactor_add_missing_imports(self):
     return autoimport.get_changes(self.resource.real_path)