Exemplo n.º 1
0
class RopeFolderTest(unittest.TestCase):
    def setUp(self):
        super(RopeFolderTest, self).setUp()
        self.project = None

    def tearDown(self):
        if self.project:
            testutils.remove_project(self.project)
        super(RopeFolderTest, self).tearDown()

    def test_none_project_rope_folder(self):
        self.project = testutils.sample_project(ropefolder=None)
        self.assertTrue(self.project.ropefolder is None)

    def test_getting_project_rope_folder(self):
        self.project = testutils.sample_project(ropefolder='.ropeproject')
        self.assertTrue(self.project.ropefolder.exists())
        self.assertTrue('.ropeproject', self.project.ropefolder.path)

    def test_setting_ignored_resources(self):
        self.project = testutils.sample_project(
            ignored_resources=['myfile.txt'])
        myfile = self.project.get_file('myfile.txt')
        file2 = self.project.get_file('file2.txt')
        self.assertTrue(self.project.is_ignored(myfile))
        self.assertFalse(self.project.is_ignored(file2))

    def test_ignored_folders(self):
        self.project = testutils.sample_project(ignored_resources=['myfolder'])
        myfolder = self.project.root.create_folder('myfolder')
        self.assertTrue(self.project.is_ignored(myfolder))
        myfile = myfolder.create_file('myfile.txt')
        self.assertTrue(self.project.is_ignored(myfile))

    def test_ignored_resources_and_get_files(self):
        self.project = testutils.sample_project(
            ignored_resources=['myfile.txt'], ropefolder=None)
        myfile = self.project.get_file('myfile.txt')
        self.assertEquals(0, len(self.project.get_files()))
        myfile.create()
        self.assertEquals(0, len(self.project.get_files()))

    def test_ignored_resources_and_get_files2(self):
        self.project = testutils.sample_project(
            ignored_resources=['myfile.txt'], ropefolder=None)
        myfile = self.project.root.create_file('myfile.txt')  # noqa
        self.assertEquals(0, len(self.project.get_files()))

    def test_setting_ignored_resources_patterns(self):
        self.project = testutils.sample_project(ignored_resources=['m?file.*'])
        myfile = self.project.get_file('myfile.txt')
        file2 = self.project.get_file('file2.txt')
        self.assertTrue(self.project.is_ignored(myfile))
        self.assertFalse(self.project.is_ignored(file2))

    def test_star_should_not_include_slashes(self):
        self.project = testutils.sample_project(ignored_resources=['f*.txt'])
        folder = self.project.root.create_folder('folder')
        file1 = folder.create_file('myfile.txt')
        file2 = folder.create_file('file2.txt')
        self.assertFalse(self.project.is_ignored(file1))
        self.assertTrue(self.project.is_ignored(file2))

    def test_normal_fscommands(self):
        fscommands = _MockFSCommands()
        self.project = testutils.sample_project(fscommands=fscommands)
        myfile = self.project.get_file('myfile.txt')
        myfile.create()
        self.assertTrue('create_file ', fscommands.log)

    def test_fscommands_and_ignored_resources(self):
        fscommands = _MockFSCommands()
        self.project = testutils.sample_project(
            fscommands=fscommands,
            ignored_resources=['myfile.txt'],
            ropefolder=None)
        myfile = self.project.get_file('myfile.txt')
        myfile.create()
        self.assertEquals('', fscommands.log)

    def test_ignored_resources_and_prefixes(self):
        self.project = testutils.sample_project(ignored_resources=['.hg'])
        myfile = self.project.root.create_file('.hgignore')
        self.assertFalse(self.project.is_ignored(myfile))

    def test_loading_config_dot_py(self):
        self.project = testutils.sample_project(ropefolder='.ropeproject')
        config = self.project.get_file('.ropeproject/config.py')
        if not config.exists():
            config.create()
        config.write('def set_prefs(prefs):\n'
                     '    prefs["ignored_resources"] = ["myfile.txt"]\n'
                     'def project_opened(project):\n'
                     '    project.root.create_file("loaded")\n')
        self.project.close()
        self.project = Project(self.project.address, ropefolder='.ropeproject')
        self.assertTrue(self.project.get_file('loaded').exists())
        myfile = self.project.get_file('myfile.txt')
        self.assertTrue(self.project.is_ignored(myfile))

    def test_ignoring_syntax_errors(self):
        self.project = testutils.sample_project(ropefolder=None,
                                                ignore_syntax_errors=True)
        mod = testutils.create_module(self.project, 'mod')
        mod.write('xyz print')
        pymod = self.project.get_pymodule(mod)  # noqa

    def test_compressed_history(self):
        self.project = testutils.sample_project(compress_history=True)
        mod = testutils.create_module(self.project, 'mod')
        mod.write('')

    def test_compressed_objectdb(self):
        self.project = testutils.sample_project(compress_objectdb=True)
        mod = testutils.create_module(self.project, 'mod')
        self.project.pycore.analyze_module(mod)

    def test_nested_dot_ropeproject_folder(self):
        self.project = testutils.sample_project(ropefolder='.f1/f2')
        ropefolder = self.project.ropefolder
        self.assertEquals('.f1/f2', ropefolder.path)
        self.assertTrue(ropefolder.exists())
Exemplo n.º 2
0
class RopeFolderTest(unittest.TestCase):
    def setUp(self):
        super(RopeFolderTest, self).setUp()
        self.project = None

    def tearDown(self):
        if self.project:
            testutils.remove_project(self.project)
        super(RopeFolderTest, self).tearDown()

    def test_none_project_rope_folder(self):
        self.project = testutils.sample_project(ropefolder=None)
        self.assertTrue(self.project.ropefolder is None)

    def test_getting_project_rope_folder(self):
        self.project = testutils.sample_project(ropefolder=".ropeproject")
        self.assertTrue(self.project.ropefolder.exists())
        self.assertTrue(".ropeproject", self.project.ropefolder.path)

    def test_setting_ignored_resources(self):
        self.project = testutils.sample_project(
            ignored_resources=["myfile.txt"])
        myfile = self.project.get_file("myfile.txt")
        file2 = self.project.get_file("file2.txt")
        self.assertTrue(self.project.is_ignored(myfile))
        self.assertFalse(self.project.is_ignored(file2))

    def test_ignored_folders(self):
        self.project = testutils.sample_project(ignored_resources=["myfolder"])
        myfolder = self.project.root.create_folder("myfolder")
        self.assertTrue(self.project.is_ignored(myfolder))
        myfile = myfolder.create_file("myfile.txt")
        self.assertTrue(self.project.is_ignored(myfile))

    def test_ignored_resources_and_get_files(self):
        self.project = testutils.sample_project(
            ignored_resources=["myfile.txt"], ropefolder=None)
        myfile = self.project.get_file("myfile.txt")
        self.assertEqual(0, len(self.project.get_files()))
        myfile.create()
        self.assertEqual(0, len(self.project.get_files()))

    def test_ignored_resources_and_get_files2(self):
        self.project = testutils.sample_project(
            ignored_resources=["myfile.txt"], ropefolder=None)
        myfile = self.project.root.create_file("myfile.txt")  # noqa
        self.assertEqual(0, len(self.project.get_files()))

    def test_setting_ignored_resources_patterns(self):
        self.project = testutils.sample_project(ignored_resources=["m?file.*"])
        myfile = self.project.get_file("myfile.txt")
        file2 = self.project.get_file("file2.txt")
        self.assertTrue(self.project.is_ignored(myfile))
        self.assertFalse(self.project.is_ignored(file2))

    def test_star_should_not_include_slashes(self):
        self.project = testutils.sample_project(ignored_resources=["f*.txt"])
        folder = self.project.root.create_folder("folder")
        file1 = folder.create_file("myfile.txt")
        file2 = folder.create_file("file2.txt")
        self.assertFalse(self.project.is_ignored(file1))
        self.assertTrue(self.project.is_ignored(file2))

    def test_normal_fscommands(self):
        fscommands = _MockFSCommands()
        self.project = testutils.sample_project(fscommands=fscommands)
        myfile = self.project.get_file("myfile.txt")
        myfile.create()
        self.assertTrue("create_file ", fscommands.log)

    def test_fscommands_and_ignored_resources(self):
        fscommands = _MockFSCommands()
        self.project = testutils.sample_project(
            fscommands=fscommands,
            ignored_resources=["myfile.txt"],
            ropefolder=None)
        myfile = self.project.get_file("myfile.txt")
        myfile.create()
        self.assertEqual("", fscommands.log)

    def test_deprecated_fscommands(self):
        fscommands = _DeprecatedFSCommands()
        self.project = testutils.sample_project(fscommands=fscommands)
        myfile = self.project.get_file("myfile.txt")
        myfile.create()
        self.assertTrue("create_file ", fscommands.log)

    def test_ignored_resources_and_prefixes(self):
        self.project = testutils.sample_project(ignored_resources=[".hg"])
        myfile = self.project.root.create_file(".hgignore")
        self.assertFalse(self.project.is_ignored(myfile))

    def test_loading_config_dot_py(self):
        self.project = testutils.sample_project(ropefolder=".ropeproject")
        config = self.project.get_file(".ropeproject/config.py")
        if not config.exists():
            config.create()
        config.write(
            dedent("""\
                def set_prefs(prefs):
                    prefs["ignored_resources"] = ["myfile.txt"]
                def project_opened(project):
                    project.root.create_file("loaded")
            """))
        self.project.close()
        self.project = Project(self.project.address, ropefolder=".ropeproject")
        self.assertTrue(self.project.get_file("loaded").exists())
        myfile = self.project.get_file("myfile.txt")
        self.assertTrue(self.project.is_ignored(myfile))

    def test_ignoring_syntax_errors(self):
        self.project = testutils.sample_project(ropefolder=None,
                                                ignore_syntax_errors=True)
        mod = testutils.create_module(self.project, "mod")
        mod.write("xyz print")
        pymod = self.project.get_pymodule(mod)  # noqa

    def test_compressed_history(self):
        self.project = testutils.sample_project(compress_history=True)
        mod = testutils.create_module(self.project, "mod")
        mod.write("")

    def test_compressed_objectdb(self):
        self.project = testutils.sample_project(compress_objectdb=True)
        mod = testutils.create_module(self.project, "mod")
        self.project.pycore.analyze_module(mod)

    def test_nested_dot_ropeproject_folder(self):
        self.project = testutils.sample_project(ropefolder=".f1/f2")
        ropefolder = self.project.ropefolder
        self.assertEqual(".f1/f2", ropefolder.path)
        self.assertTrue(ropefolder.exists())
Exemplo n.º 3
0
class RopeFolderTest(unittest.TestCase):
    def setUp(self):
        super(RopeFolderTest, self).setUp()
        self.project = None

    def tearDown(self):
        if self.project:
            testutils.remove_project(self.project)
        super(RopeFolderTest, self).tearDown()

    def test_none_project_rope_folder(self):
        self.project = testutils.sample_project(ropefolder=None)
        self.assertTrue(self.project.ropefolder is None)

    def test_getting_project_rope_folder(self):
        self.project = testutils.sample_project(ropefolder=".ropeproject")
        self.assertTrue(self.project.ropefolder.exists())
        self.assertTrue(".ropeproject", self.project.ropefolder.path)

    def test_setting_ignored_resources(self):
        self.project = testutils.sample_project(ignored_resources=["myfile.txt"])
        myfile = self.project.get_file("myfile.txt")
        file2 = self.project.get_file("file2.txt")
        self.assertTrue(self.project.is_ignored(myfile))
        self.assertFalse(self.project.is_ignored(file2))

    def test_ignored_folders(self):
        self.project = testutils.sample_project(ignored_resources=["myfolder"])
        myfolder = self.project.root.create_folder("myfolder")
        self.assertTrue(self.project.is_ignored(myfolder))
        myfile = myfolder.create_file("myfile.txt")
        self.assertTrue(self.project.is_ignored(myfile))

    def test_ignored_resources_and_get_files(self):
        self.project = testutils.sample_project(ignored_resources=["myfile.txt"], ropefolder=None)
        myfile = self.project.get_file("myfile.txt")
        self.assertEquals(0, len(self.project.get_files()))
        myfile.create()
        self.assertEquals(0, len(self.project.get_files()))

    def test_ignored_resources_and_get_files2(self):
        self.project = testutils.sample_project(ignored_resources=["myfile.txt"], ropefolder=None)
        myfile = self.project.root.create_file("myfile.txt")
        self.assertEquals(0, len(self.project.get_files()))

    def test_setting_ignored_resources_patterns(self):
        self.project = testutils.sample_project(ignored_resources=["m?file.*"])
        myfile = self.project.get_file("myfile.txt")
        file2 = self.project.get_file("file2.txt")
        self.assertTrue(self.project.is_ignored(myfile))
        self.assertFalse(self.project.is_ignored(file2))

    def test_star_should_not_include_slashes(self):
        self.project = testutils.sample_project(ignored_resources=["f*.txt"])
        folder = self.project.root.create_folder("folder")
        file1 = folder.create_file("myfile.txt")
        file2 = folder.create_file("file2.txt")
        self.assertFalse(self.project.is_ignored(file1))
        self.assertTrue(self.project.is_ignored(file2))

    def test_normal_fscommands(self):
        fscommands = _MockFSCommands()
        self.project = testutils.sample_project(fscommands=fscommands)
        myfile = self.project.get_file("myfile.txt")
        myfile.create()
        self.assertTrue("create_file ", fscommands.log)

    def test_fscommands_and_ignored_resources(self):
        fscommands = _MockFSCommands()
        self.project = testutils.sample_project(
            fscommands=fscommands, ignored_resources=["myfile.txt"], ropefolder=None
        )
        myfile = self.project.get_file("myfile.txt")
        myfile.create()
        self.assertEquals("", fscommands.log)

    def test_ignored_resources_and_prefixes(self):
        self.project = testutils.sample_project(ignored_resources=[".hg"])
        myfile = self.project.root.create_file(".hgignore")
        self.assertFalse(self.project.is_ignored(myfile))

    def test_loading_config_dot_py(self):
        self.project = testutils.sample_project(ropefolder=".ropeproject")
        config = self.project.get_file(".ropeproject/config.py")
        if not config.exists():
            config.create()
        config.write(
            "def set_prefs(prefs):\n"
            '    prefs["ignored_resources"] = ["myfile.txt"]\n'
            "def project_opened(project):\n"
            '    project.root.create_file("loaded")\n'
        )
        self.project.close()
        self.project = Project(self.project.address, ropefolder=".ropeproject")
        self.assertTrue(self.project.get_file("loaded").exists())
        myfile = self.project.get_file("myfile.txt")
        self.assertTrue(self.project.is_ignored(myfile))

    def test_ignoring_syntax_errors(self):
        self.project = testutils.sample_project(ropefolder=None, ignore_syntax_errors=True)
        pycore = self.project.pycore
        mod = testutils.create_module(self.project, "mod")
        mod.write("xyz print")
        pymod = pycore.resource_to_pyobject(mod)

    def test_compressed_history(self):
        self.project = testutils.sample_project(compress_history=True)
        mod = testutils.create_module(self.project, "mod")
        mod.write("")

    def test_compressed_objectdb(self):
        self.project = testutils.sample_project(compress_objectdb=True)
        mod = testutils.create_module(self.project, "mod")
        self.project.pycore.analyze_module(mod)

    def test_nested_dot_ropeproject_folder(self):
        self.project = testutils.sample_project(ropefolder=".f1/f2")
        ropefolder = self.project.ropefolder
        self.assertEquals(".f1/f2", ropefolder.path)
        self.assertTrue(ropefolder.exists())
Exemplo n.º 4
0
class RopeFolderTest(unittest.TestCase):

    def setUp(self):
        super(RopeFolderTest, self).setUp()
        self.project = None

    def tearDown(self):
        if self.project:
            testutils.remove_project(self.project)
        super(RopeFolderTest, self).tearDown()

    def test_none_project_rope_folder(self):
        self.project = testutils.sample_project(ropefolder=None)
        self.assertTrue(self.project.ropefolder is None)

    def test_getting_project_rope_folder(self):
        self.project = testutils.sample_project(ropefolder='.ropeproject')
        self.assertTrue(self.project.ropefolder.exists())
        self.assertTrue('.ropeproject', self.project.ropefolder.path)

    def test_setting_ignored_resources(self):
        self.project = testutils.sample_project(
            ignored_resources=['myfile.txt'])
        myfile = self.project.get_file('myfile.txt')
        file2 = self.project.get_file('file2.txt')
        self.assertTrue(self.project.is_ignored(myfile))
        self.assertFalse(self.project.is_ignored(file2))

    def test_ignored_folders(self):
        self.project = testutils.sample_project(ignored_resources=['myfolder'])
        myfolder = self.project.root.create_folder('myfolder')
        self.assertTrue(self.project.is_ignored(myfolder))
        myfile = myfolder.create_file('myfile.txt')
        self.assertTrue(self.project.is_ignored(myfile))

    def test_ignored_resources_and_get_files(self):
        self.project = testutils.sample_project(
            ignored_resources=['myfile.txt'], ropefolder=None)
        myfile = self.project.get_file('myfile.txt')
        self.assertEquals(0, len(self.project.get_files()))
        myfile.create()
        self.assertEquals(0, len(self.project.get_files()))

    def test_ignored_resources_and_get_files2(self):
        self.project = testutils.sample_project(
            ignored_resources=['myfile.txt'], ropefolder=None)
        myfile = self.project.root.create_file('myfile.txt')  # noqa
        self.assertEquals(0, len(self.project.get_files()))

    def test_setting_ignored_resources_patterns(self):
        self.project = testutils.sample_project(ignored_resources=['m?file.*'])
        myfile = self.project.get_file('myfile.txt')
        file2 = self.project.get_file('file2.txt')
        self.assertTrue(self.project.is_ignored(myfile))
        self.assertFalse(self.project.is_ignored(file2))

    def test_star_should_not_include_slashes(self):
        self.project = testutils.sample_project(ignored_resources=['f*.txt'])
        folder = self.project.root.create_folder('folder')
        file1 = folder.create_file('myfile.txt')
        file2 = folder.create_file('file2.txt')
        self.assertFalse(self.project.is_ignored(file1))
        self.assertTrue(self.project.is_ignored(file2))

    def test_normal_fscommands(self):
        fscommands = _MockFSCommands()
        self.project = testutils.sample_project(fscommands=fscommands)
        myfile = self.project.get_file('myfile.txt')
        myfile.create()
        self.assertTrue('create_file ', fscommands.log)

    def test_fscommands_and_ignored_resources(self):
        fscommands = _MockFSCommands()
        self.project = testutils.sample_project(
            fscommands=fscommands,
            ignored_resources=['myfile.txt'], ropefolder=None)
        myfile = self.project.get_file('myfile.txt')
        myfile.create()
        self.assertEquals('', fscommands.log)

    def test_ignored_resources_and_prefixes(self):
        self.project = testutils.sample_project(
            ignored_resources=['.hg'])
        myfile = self.project.root.create_file('.hgignore')
        self.assertFalse(self.project.is_ignored(myfile))

    def test_loading_config_dot_py(self):
        self.project = testutils.sample_project(ropefolder='.ropeproject')
        config = self.project.get_file('.ropeproject/config.py')
        if not config.exists():
            config.create()
        config.write('def set_prefs(prefs):\n'
                     '    prefs["ignored_resources"] = ["myfile.txt"]\n'
                     'def project_opened(project):\n'
                     '    project.root.create_file("loaded")\n')
        self.project.close()
        self.project = Project(self.project.address, ropefolder='.ropeproject')
        self.assertTrue(self.project.get_file('loaded').exists())
        myfile = self.project.get_file('myfile.txt')
        self.assertTrue(self.project.is_ignored(myfile))

    def test_ignoring_syntax_errors(self):
        self.project = testutils.sample_project(ropefolder=None,
                                                ignore_syntax_errors=True)
        mod = testutils.create_module(self.project, 'mod')
        mod.write('xyz print')
        pymod = self.project.get_pymodule(mod)  # noqa

    def test_compressed_history(self):
        self.project = testutils.sample_project(compress_history=True)
        mod = testutils.create_module(self.project, 'mod')
        mod.write('')

    def test_compressed_objectdb(self):
        self.project = testutils.sample_project(compress_objectdb=True)
        mod = testutils.create_module(self.project, 'mod')
        self.project.pycore.analyze_module(mod)

    def test_nested_dot_ropeproject_folder(self):
        self.project = testutils.sample_project(ropefolder='.f1/f2')
        ropefolder = self.project.ropefolder
        self.assertEquals('.f1/f2', ropefolder.path)
        self.assertTrue(ropefolder.exists())