示例#1
0
    def test_completionDot(self):
        """
        A '.' target generates completions for the whole directory
        """
        cwd = os.getcwd()
        tmpdir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, tmpdir)
        os.chdir(tmpdir)
        self.addCleanup(os.chdir, cwd)
        os.mkdir('my_pkg')
        fh = open(os.path.join('my_pkg', '__init__.py'), 'w')
        fh.write('')
        fh.close()
        fh = open(os.path.join('my_pkg', 'test_things.py'), 'w')
        fh.write(dedent(
            """
            import unittest

            class A(unittest.TestCase):
                def testOne(self):
                    pass
                def testTwo(self):
                    pass
            """))
        fh.close()
        c = set(loader.getCompletions('.').split('\n'))
        self.assertIn('my_pkg', c)
        self.assertIn('my_pkg.test_things', c)
        self.assertIn('my_pkg.test_things.A.testOne', c)
        self.assertIn('my_pkg.test_things.A.testTwo', c)
示例#2
0
 def test_completionPartial(self):
     """
     Correct completions generated for partial match.  2nd target ignored.
     """
     c = set(loader.getCompletions(['fetchdata.te', 'fetchdata']).split('\n'))
     self.assertIn('fetchdata.test', c)
     self.assertIn('fetchdata.test.test_loader', c)
     self.assertIn('fetchdata.test.test_loader.TestCompletions', c)
     self.assertIn(
         'fetchdata.test.test_loader.TestCompletions.test_completionPartial', c)
     self.assertNotIn('fetchdata', c)
示例#3
0
 def test_completionExact(self):
     """
     Correct completions are generated for an exact match.
     """
     c = set(loader.getCompletions('fetchdata').split('\n'))
     self.assertIn('fetchdata', c)
     self.assertIn('fetchdata.test', c)
     self.assertIn('fetchdata.test.test_loader', c)
     self.assertIn('fetchdata.test.test_loader.TestCompletions', c)
     self.assertIn(
             'fetchdata.test.test_loader.TestCompletions.test_completionExact', c)
示例#4
0
 def test_completionPartialShort(self):
     """
     Correct completions generated for short partial match.
     """
     cwd = os.getcwd()
     fetchdata_parent = dirname(dirname(dirname(os.path.abspath(__file__))))
     os.chdir(fetchdata_parent)
     self.addCleanup(os.chdir, cwd)
     c = set(loader.getCompletions('gre').split('\n'))
     self.assertIn('fetchdata', c)
     self.assertIn('fetchdata.test', c)
     self.assertIn('fetchdata.test.test_loader', c)
     self.assertIn('fetchdata.test.test_loader.TestCompletions', c)
     self.assertIn(
         'fetchdata.test.test_loader.TestCompletions.test_completionPartialShort', c)
示例#5
0
    def test_completionIgnoresErrors(self):
        """
        Errors in one module don't block the remaining completions
        """
        cwd = os.getcwd()
        tmpdir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, tmpdir)
        os.chdir(tmpdir)
        self.addCleanup(os.chdir, cwd)
        os.mkdir('my_pkg2')
        fh = open(os.path.join('my_pkg2', '__init__.py'), 'w')
        fh.write('')
        fh.close()
        fh = open(os.path.join('my_pkg2', 'test_crash01.py'), 'w')
        contents = dedent(
            """
            import unittest

            class A(unittest.TestCase):
                def testOne(self):
                    pass
                def testTwo(self):
                    pass
            """)
        fh.write(contents)
        fh.close()
        fh = open(os.path.join('my_pkg2', 'test_crash02.py'), 'w')
        fh.write("import moocow")
        fh.close()
        fh = open(os.path.join('my_pkg2', 'test_crash03.py'), 'w')
        fh.write(contents)
        fh.close()
        c = set(loader.getCompletions('.').split('\n'))
        self.assertIn('my_pkg2', c)
        self.assertIn('my_pkg2.test_crash01', c)
        self.assertIn('my_pkg2.test_crash01.A.testOne', c)
        self.assertIn('my_pkg2.test_crash01.A.testTwo', c)
        self.assertIn('my_pkg2.test_crash03', c)
        self.assertIn('my_pkg2.test_crash03.A.testOne', c)
        self.assertIn('my_pkg2.test_crash03.A.testTwo', c)
示例#6
0
 def test_completionBad(self):
     """
     Bad match generates no completions
     """
     self.assertEqual('', loader.getCompletions('garbage.in'))