Esempio n. 1
0
 def testIgorPrinted(self):
     hold_stdout = sys.stdout
     sys.stdout = out = StringIO()
     igor('--print', self.filename)
     sys.stdout = hold_stdout
     self.assertEqual(out.getvalue(), self.expected)
     # make sure the file wasn't touched
     self.assertEqual(open(self.filename).read(), "bar\nbaz\n")
Esempio n. 2
0
 def testPrintModeDoesNothingOnSyntaxError(self):
     f = open(self.filename, 'w')
     f.write('from')
     f.close()
     
     hold_stdout = sys.stdout
     sys.stdout = out = StringIO()
     igor('--print', self.filename)
     sys.stdout = hold_stdout
     self.assertEqual(out.getvalue(), 'from')
Esempio n. 3
0
    def testIgorReapMode(self):
        # make sure db starts empty
        os.unlink(checker.IMPORT_DB_FNAME + '.db')

        hold_stdout = sys.stdout
        sys.stdout = out = StringIO()
        igor('--reap', self.filename)
        sys.stdout = hold_stdout
        
        self.failIf(out.getvalue())
        self.failUnless(open(checker.IMPORT_DB_FNAME + '.db').read())
Esempio n. 4
0
    def testInitialSimpleComments(self):
        f = open(self.filename, 'w')
        f.write('# -*- coding: utf8 -*-\nbar\nbaz\n')
        f.close()

        expected = "# -*- coding: utf8 -*-\nfrom foo import bar\nfrom foo import baz\nbar\nbaz\n"

        igor(self.filename)
        f = open(self.filename)
        self.assertEqual(f.read(), expected)
        f.close()
Esempio n. 5
0
 def testIgorPrintsOriginalIfNoImportsFound(self):
     # make sure the original file is still output in print mode
     # if Igor found no new imports
     f = open(self.filename, 'w')
     f.write('qux')
     f.close()
     
     hold_stdout = sys.stdout
     sys.stdout = out = StringIO()
     igor('--print', self.filename)
     sys.stdout = hold_stdout
     self.assertEqual(out.getvalue(), 'qux')
Esempio n. 6
0
    def testIgorReapMode(self):
        # make sure test db starts empty
        if os.path.exists(TEST_DB_DIRNAME):
            shutil.rmtree(TEST_DB_DIRNAME)
        os.mkdir(TEST_DB_DIRNAME)

        f = open(self.filename, 'w')
        f.write('from foo import bar, baz')
        f.close()

        hold_stdout = sys.stdout
        sys.stdout = out = StringIO()
        igor('--reap', self.filename)
        sys.stdout = hold_stdout

        self.failIf(out.getvalue())
        self.failUnless(len(shelve.open(checker.IMPORT_DB_BASE_FILENAME)))
Esempio n. 7
0
    def setUp(self):        
        if os.path.exists(checker.IMPORT_DB_FNAME + '.db'):
            os.unlink(checker.IMPORT_DB_FNAME + '.db')

        (fd, self.filename) = tempfile.mkstemp(text=True)
        os.close(fd)
        
        # Populate db
        f = open(self.filename, 'w')
        f.write('from foo import bar, baz')
        f.close()
        igor(self.filename)
        
        # Now manually remove the import
        f = open(self.filename, 'w')
        f.write('bar\nbaz\n')
        f.close()
        
        self.expected = "from foo import bar\nfrom foo import baz\nbar\nbaz\n"
Esempio n. 8
0
    def setUp(self):
        if os.path.exists(TEST_DB_DIRNAME):
            shutil.rmtree(TEST_DB_DIRNAME)
        os.mkdir(TEST_DB_DIRNAME)

        (fd, self.filename) = tempfile.mkstemp(text=True)
        os.close(fd)

        # Populate db
        f = open(self.filename, 'w')
        f.write('from foo import bar, baz')
        f.close()
        igor(self.filename)

        # Now manually remove the import
        f = open(self.filename, 'w')
        f.write('bar\nbaz\n')
        f.close()

        self.expected = "from foo import bar\nfrom foo import baz\nbar\nbaz\n"
Esempio n. 9
0
 def testIgorInplace(self):
     # Now run Igor in normal mode and make sure the import was replaced.
     igor(self.filename)
     f = open(self.filename)
     self.assertEqual(f.read(), self.expected)
     f.close()