예제 #1
0
 def testCheckFileForLibraryNoLibraryPresent(self):
     self.setUpTempDirectory()
     self.createTempDotPyFile('here is some\nmultiline text')
     self.assertEqual(
         thaw.check_file_for_library(os.path.join(self.test_dir, 'temp.py'),
                                     'idna')['linenums'], [])
     self.tearDownTempDirectory()
예제 #2
0
 def testCheckFileForLibraryAndIdentifyVariables(self):
     text = 'import datetime #1\n#2\ndelta = datetime.timedelta(2) #3\n#4\ndelta * 2 #5'
     self.setUpTempDirectory()
     self.createTempDotPyFile(text)
     self.assertEqual(
         thaw.check_file_for_library(os.path.join(self.test_dir, 'temp.py'),
                                     'datetime')['linenums'], [3, 5])
     self.tearDownTempDirectory()
예제 #3
0
 def testCheckFileForLibraryFromLibraryImportOneModuleAsAlias(self):
     text = 'from datetime import date as d #1\n#2\nd.today() #3'
     self.setUpTempDirectory()
     self.createTempDotPyFile(text)
     self.assertEqual(
         thaw.check_file_for_library(os.path.join(self.test_dir, 'temp.py'),
                                     'datetime')['linenums'], [3])
     self.tearDownTempDirectory()
예제 #4
0
 def testCheckFileForLibraryImportLibraryAsAlias(self):
     text = 'import datetime as dt #1\n#2\nelapsed = dt.timedelta(2) #3\nelapsed2 = dt.timedelta(3) #4'
     self.setUpTempDirectory()
     self.createTempDotPyFile(text)
     self.assertEqual(
         thaw.check_file_for_library(os.path.join(self.test_dir, 'temp.py'),
                                     'datetime')['linenums'], [3, 4])
     self.tearDownTempDirectory()
예제 #5
0
 def testCheckFileForLibraryFromLibraryImportTwoModules(self):
     text = 'from datetime import date, time #1\n#2\ntoday = date.today() #3\nepoch = time.time() #4'
     self.setUpTempDirectory()
     self.createTempDotPyFile(text)
     self.assertEqual(
         thaw.check_file_for_library(os.path.join(self.test_dir, 'temp.py'),
                                     'datetime')['linenums'], [3, 4])
     self.tearDownTempDirectory()
예제 #6
0
 def testCheckFileForLibraryImportLibrary(self):
     self.setUpTempDirectory()
     self.createTempDotPyFile(
         'import idna #line1\n#line2\nprint idna.decode("xn--eckwd4c7c.xn--zckzah") #line3'
     )
     self.assertEqual(
         thaw.check_file_for_library(os.path.join(self.test_dir, 'temp.py'),
                                     'idna')['linenums'], [3])
     self.tearDownTempDirectory()
예제 #7
0
 def testCheckFileForLibraryImportLibraryButLibraryNameIsInComment(self):
     self.setUpTempDirectory()
     self.createTempDotPyFile(
         'import idna\nx = 3\ny = 4\nz = x + y # this does not actually use the idna library'
     )
     self.assertEqual(
         thaw.check_file_for_library(os.path.join(self.test_dir, 'temp.py'),
                                     'idna')['linenums'], [])
     self.tearDownTempDirectory()