Exemplo n.º 1
0
    def testOffline(self):
        """
        Tests if install from the dowload-cache works.
        """
        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest
download-cache = %(cache)s

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
        """ % {'repo' : self.temprepo, 'cache': self.tempcache})

        # First install as usual
        build = self._buildout()
        self.assertFalse(build['gittest'].recipe.installed_from_cache)

        # clear buildout
        os.unlink(os.path.join(build['buildout']['directory'], '.installed.cfg'))
        testing.rmdir(build['buildout']['directory'], 'parts')

        # now install from cache
        build = self._buildout([('buildout', 'install-from-cache', 'true')])
        self.assertTrue(build['gittest'].recipe.installed_from_cache)
        build = self._buildout([('buildout', 'install-from-cache', 'true')])
Exemplo n.º 2
0
    def testOffline(self):
        """
        Tests if install from the dowload-cache works.
        """
        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest
download-cache = %(cache)s

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
        """ % {'repo': self.temprepo, 'cache': self.tempcache})

        # First install as usual
        build = self._buildout()
        self.assertFalse(build['gittest'].recipe.installed_from_cache)

        # clear buildout
        os.unlink(os.path.join(build['buildout']['directory'], '.installed.cfg'))
        testing.rmdir(build['buildout']['directory'], 'parts')

        # now install from cache
        build = self._buildout([('buildout', 'install-from-cache', 'true')])
        self.assertTrue(build['gittest'].recipe.installed_from_cache)
        build = self._buildout([('buildout', 'install-from-cache', 'true')])
Exemplo n.º 3
0
    def testOffline(self):
        """
        Tests if install from the dowload-cache works.
        """
        testing.write(
            self.tempdir,
            "buildout.cfg",
            """
[buildout]
parts = gittest
download-cache = %(cache)s

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
        """
            % {"repo": self.temprepo, "cache": self.tempcache},
        )

        # First install as usual
        build = self._buildout()
        self.assertFalse(build["gittest"].recipe.installed_from_cache)

        # clear buildout
        os.unlink(os.path.join(build["buildout"]["directory"], ".installed.cfg"))
        testing.rmdir(build["buildout"]["directory"], "parts")

        # now install from cache
        build = self._buildout([("buildout", "install-from-cache", "true")])
        self.assertTrue(build["gittest"].recipe.installed_from_cache)
Exemplo n.º 4
0
    def test_uninstall(self):
        """ """
        from ..recipes import Recipe
        from ..recipes import uninstall

        recipe_options = self.recipe_options.copy()
        self.buildout['sublimetext'] = recipe_options

        recipe = Recipe(self.buildout, 'sublimetext',
                        self.buildout['sublimetext'])
        recipe._set_defaults()

        # Test: in case of overwrite false, project file should not be removed
        filename = recipe.options['project-name'] + '.sublime-project'
        write(
            self.location,
            filename,
            '{"hello": "T20"}',
        )
        uninstall(recipe.name, recipe.options)

        # should be exists
        self.assertTrue(os.path.exists(filename))

        # update to overwrite True
        recipe.options.update({'overwrite': 'True'})
        uninstall(recipe.name, recipe.options)

        # now should be removed
        self.assertFalse(os.path.exists(filename))
Exemplo n.º 5
0
    def test__set_defaults(self):
        """ """
        from ..recipes import Recipe
        buildout = self.buildout
        recipe_options = self.recipe_options.copy()

        del recipe_options['project-name']

        buildout['sublimetext'] = recipe_options
        recipe = Recipe(buildout, 'sublimetext', buildout['sublimetext'])

        recipe._set_defaults()
        # Test: default project name should be buildout directory name
        self.assertEqual(
            recipe.options['project-name'],
            self.location.split('/')[-1],
        )

        # Test: if any ``sublime-project`` suffix file is available inside buildout directory
        # that should be picked as default project file name
        _project_file = 'human_project'
        write(self.location, _project_file + '.sublime-project', '[]')
        # clear previously assaigned default
        del buildout['sublimetext']['project-name']

        recipe = Recipe(buildout, 'sublimetext', buildout['sublimetext'])
        recipe._set_defaults()

        self.assertEqual(recipe.options['project-name'], _project_file)
Exemplo n.º 6
0
def create_setup_py(loc, name, version='1.0', other=''):
    """Create a setup.py."""
    # One would think zc.buildout.testing would provide
    # something to this effect.
    from zc.buildout.testing import write
    write(
        loc, 'setup.py', """\
from setuptools import setup, find_packages
setup(name='%(name)s', version='%(version)s', zip_safe=False, packages=find_packages(), %(other)s)
""" % dict(name=name, version=version, other=other))
    write(loc, '%s.py' % name, "#\n")
Exemplo n.º 7
0
    def testSingleEgg(self):
        repo = os.path.join(os.path.dirname(FILE), '../../../')
        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
as_egg = true
        """ % {'repo': repo})
        buildout = self._buildout()
        installs = os.listdir(buildout['buildout']['develop-eggs-directory'])
        self.assertTrue('zerokspot.recipe.git.egg-link' in installs)
Exemplo n.º 8
0
    def testSingleEgg(self):
        repo = 'git://github.com/zerok/zerokspot.gitrecipe.git'
        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
as_egg = true
        """ % {'repo': repo})
        buildout = self._buildout()
        installs = os.listdir(buildout['buildout']['develop-eggs-directory'])
        self.assertTrue('zerokspot.recipe.git.egg-link' in installs)
Exemplo n.º 9
0
    def testSingleEgg(self):
        repo = 'git://github.com/zerok/zerokspot.gitrecipe.git'
        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
as_egg = true
        """ % {'repo': repo})
        buildout = self._buildout()
        installs = os.listdir(buildout['buildout']['develop-eggs-directory'])
        self.assertTrue('zerokspot.recipe.git.egg-link' in installs)
Exemplo n.º 10
0
    def testFetch(self):
        """
        Tests if the basic cloning and updating of the repository works.
        """

        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
        """ % {'repo': self.temprepo})
        self._buildout()
        self.assertTrue(os.path.exists(os.path.join(self.tempdir, 'parts', 'gittest', 'test.txt')))
        self._buildout()
Exemplo n.º 11
0
    def testFetch(self):
        """
        Tests if the basic cloning and updating of the repository works.
        """

        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
        """ % {'repo' : self.temprepo})
        self._buildout()
        self.assertTrue(os.path.exists(os.path.join(self.tempdir, 'parts', 'gittest', 'test.txt')))
        self._buildout()
Exemplo n.º 12
0
    def testBasic(self):
        testing.write(self.projectdir, 'buildout.cfg', """
[buildout]
parts = gittest

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
as_egg = true
paths =
    project0
    project1
""" % {'repo': self.temprepo})
        buildout = do_buildout(os.path.join(self.projectdir, 'buildout.cfg'))
        installs = os.listdir(buildout['buildout']['develop-eggs-directory'])
        self.assertTrue('project0.egg-link' in installs)
        self.assertTrue('project1.egg-link' in installs)
Exemplo n.º 13
0
    def testBasic(self):
        testing.write(self.projectdir, 'buildout.cfg', """
[buildout]
parts = gittest

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
as_egg = true
paths = 
    project0
    project1
""" % {'repo': self.temprepo})
        buildout = do_buildout(os.path.join(self.projectdir, 'buildout.cfg'))
        installs = os.listdir(buildout['buildout']['develop-eggs-directory'])
        self.assertTrue('project0.egg-link' in installs)
        self.assertTrue('project1.egg-link' in installs)
Exemplo n.º 14
0
    def testFetchToDirectory(self):
        """
        Tests if the basic cloning and updating of the repository works.
        """
        test_custom_dir = os.path.join(self.tempdir, 'test_custom_dir')
        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
directory = %(dir)s
        """ % {'repo': self.temprepo, 'dir': test_custom_dir})
        self._buildout()
        self.assertTrue(os.path.exists(os.path.join(test_custom_dir, 'test.txt')))
        self._buildout()
Exemplo n.º 15
0
    def testRaiseExceptionOnAbsentCache(self):
        """
        install-from-cache without cache should raise an exception
        """
        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest
download-cache = %(cache)s
install-from-cache = true

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
        """ % {'repo': self.temprepo, 'cache': self.tempcache})

        build = zc.buildout.buildout.Buildout(
                    os.path.join(self.tempdir, 'buildout.cfg'), [])
        self.assertRaises(zc.buildout.UserError, build.install, None)
Exemplo n.º 16
0
    def testRecursive(self):
        """
        Tests if install works for recursive clone
        """
        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest
download-cache = %(cache)s
install-from-cache = false

[gittest]
recipe = zerokspot.recipe.git
recursive = true
repository = %(repo)s
        """ % {'repo': self.temprepo, 'cache': self.tempcache})
        self._buildout()
        path = os.path.join(self.tempdir, 'parts', 'gittest', 'submodule', '.git')
        self.assertTrue(os.path.exists(path), "%s does not exist" % repr(path))
Exemplo n.º 17
0
    def testRaiseExceptionOnAbsentCache(self):
        """
        install-from-cache without cache should raise an exception
        """
        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest
download-cache = %(cache)s
install-from-cache = true

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
        """ % {'repo' : self.temprepo, 'cache': self.tempcache})

        build = zc.buildout.buildout.Buildout(
                    os.path.join(self.tempdir, 'buildout.cfg'), [])
        self.assertRaises(zc.buildout.UserError, build.install, None)
Exemplo n.º 18
0
    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        os.mkdir(os.path.join(self.tempdir, 'downloads'))

        self.tempcache = tempfile.mkdtemp()
        self.temprepos = tempfile.mkdtemp()
        self.repo_name = 'testrepo'
        self.temprepo = os.path.join(self.temprepos, self.repo_name)

        testing.mkdir(self.temprepo)

        os.chdir(self.tempdir)

        testing.system('cd %s && git init' % self.temprepo)
        testing.write(self.temprepo, 'test.txt', 'TEST')
        testing.system('cd %s && git add test.txt && git commit -m "Init"' % self.temprepo)
        testing.write(self.temprepo, 'test2.txt', 'TEST')
        testing.system('cd %s && git checkout -b test && git add test2.txt && git commit -m "Test-branch" && git checkout master' % self.temprepo)
Exemplo n.º 19
0
    def testNonstandardBranch(self):
        """
        Tests if install from the dowload-cache works with a non-standard branch.
        """
        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest
download-cache = %(cache)s

[gittest]
recipe = zerokspot.recipe.git
branch = test
repository = %(repo)s
        """ % {'repo' : self.temprepo, 'cache': self.tempcache})
        build = self._buildout()
        recipe = build['gittest'].recipe
        self.assertTrue(os.path.exists(os.path.join(recipe.cache_path, 'test2.txt')))
        self.assertTrue(os.path.exists(os.path.join(recipe.options['location'], 'test2.txt')))
        self._buildout()
Exemplo n.º 20
0
    def testRecursive(self):
        """
        Tests if install works for recursive clone
        """
        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest
download-cache = %(cache)s
install-from-cache = false

[gittest]
recipe = zerokspot.recipe.git
recursive = true
repository = %(repo)s
        """ % {'repo' : self.temprepo, 'cache': self.tempcache})
        build = self._buildout()
        from glob import glob
        path = os.path.join(self.tempdir, 'parts', 'gittest', 'submodule', '.git')
        self.assertTrue(os.path.exists(path), "%s does not exist" % repr(path))
Exemplo n.º 21
0
    def testNonstandardBranch(self):
        """
        Tests if install from the dowload-cache works with a non-standard branch.
        """
        testing.write(self.tempdir, 'buildout.cfg', """
[buildout]
parts = gittest
download-cache = %(cache)s

[gittest]
recipe = zerokspot.recipe.git
branch = test
repository = %(repo)s
        """ % {'repo': self.temprepo, 'cache': self.tempcache})
        build = self._buildout()
        recipe = build['gittest'].recipe
        self.assertTrue(os.path.exists(os.path.join(recipe.cache_path, 'test2.txt')))
        self.assertTrue(os.path.exists(os.path.join(recipe.options['location'], 'test2.txt')))
        self._buildout()
Exemplo n.º 22
0
    def setUp(self):
        self.location = os.getcwd()

        # Here we build a sample buildout
        self.tmp = tempfile.mkdtemp(prefix='sample-buildout')
        write(self.tmp, 'buildout.cfg', BUILDOUT_CFG)
        mkdir(self.tmp, 'sample_working_dir')
        mkdir(self.tmp, 'bugfix1')
        mkdir(self.tmp, 'bugfix1', 'bugfix1')
        write(self.tmp, 'bugfix1', 'bugfix1', '__init__.py', '')
        write(self.tmp, 'bugfix1', 'bugfix1', 'tests.py', TESTS_PY)
        write(self.tmp, 'bugfix1', 'setup.py', SETUP_PY)
        write(self.tmp, 'bugfix1', 'README.rst', '')

        os.chdir(self.tmp)
        zc.buildout.buildout.Buildout(
            'buildout.cfg',
            [('buildout', 'log-level', 'WARNING')]
        ).init('fake-argument')
Exemplo n.º 23
0
    def testFetch(self):
        """
        Tests if the basic cloning of the repository works.
        """

        testing.write(
            self.tempdir,
            "buildout.cfg",
            """
[buildout]
parts = gittest

[gittest]
recipe = zerokspot.recipe.git
repository = %(repo)s
        """
            % {"repo": self.temprepo},
        )
        self._buildout()
        self.assertTrue(os.path.exists(os.path.join(self.tempdir, "parts", "gittest", "test.txt")))
Exemplo n.º 24
0
def create_celery_egg(test):
    """Create a dummy celery egg for testing.
       The included scripts simply print the content of the celeryconfig
       module.
    """
    from zc.buildout.testing import write
    dest = test.globs['sample_eggs']
    tmp = tempfile.mkdtemp()
    try:
        write(tmp, 'README.txt', '')
        write(tmp, 'celery.py',
              'import celeryconfig\n'
              'def main():\n'
              ' print "\\n".join(["%s=%s" % (opt, repr(getattr(celeryconfig, '
              'opt))) for opt in dir(celeryconfig) if opt[0].isalpha()])\n')
        write(tmp, 'setup.py',
              "from setuptools import setup\n"
              "setup(name='celery', py_modules=['celery'],"
              " entry_points={'console_scripts': ['celeryd = celery:main', "
                                                 "'celeryctl = celery:main']},"
              " zip_safe=True, version='2.3.1')\n")
        bdist_egg(tmp, sys.executable, dest)

    finally:
        shutil.rmtree(tmp)
Exemplo n.º 25
0
    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        os.mkdir(os.path.join(self.tempdir, 'downloads'))

        self.tempcache = tempfile.mkdtemp()
        self.temprepos = tempfile.mkdtemp()
        self.repo_name = 'testrepo'
        self.temprepo = os.path.join(self.temprepos, self.repo_name)

        testing.mkdir(self.temprepo)

        os.chdir(self.tempdir)

        testing.system('cd %s && git init' % self.temprepo)
        testing.write(self.temprepo, 'test.txt', 'TEST')
        testing.system('cd %s && git add test.txt && git commit -m "Init"' % self.temprepo)
        testing.write(self.temprepo, 'test2.txt', 'TEST')
        submodule_path = os.path.join(self.temprepo, 'submodule_repo')
        testing.system('mkdir -p %s && cd %s && git init && echo 1 > file && git add file && git commit -m file' % (submodule_path, submodule_path))
        self.assertTrue(os.path.exists(os.path.join(submodule_path, '.git')))
        testing.system('cd %s && git submodule add %s submodule && git add .gitmodules && git commit -m submodule' % (self.temprepo, submodule_path))
        self.assertTrue(os.path.exists(os.path.join(self.temprepo, '.gitmodules')))
        testing.system('cd %s && git checkout -b test && git add test2.txt && git commit -m "Test-branch" && git checkout master' % self.temprepo)
Exemplo n.º 26
0
    def testNonstandardBranch(self):
        """
        Tests if install from the dowload-cache works with a non-standard branch.
        """
        testing.write(
            self.tempdir,
            "buildout.cfg",
            """
[buildout]
parts = gittest
download-cache = %(cache)s

[gittest]
recipe = zerokspot.recipe.git
branch = test
repository = %(repo)s
        """
            % {"repo": self.temprepo, "cache": self.tempcache},
        )
        build = self._buildout()
        recipe = build["gittest"].recipe
        self.assertTrue(os.path.exists(os.path.join(recipe.cache_path, "test2.txt")))
        self.assertTrue(os.path.exists(os.path.join(recipe.options["location"], "test2.txt")))
Exemplo n.º 27
0
    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        os.mkdir(os.path.join(self.tempdir, 'downloads'))

        self.tempcache = tempfile.mkdtemp()
        self.temprepos = tempfile.mkdtemp()
        self.repo_name = 'testrepo'
        self.temprepo = os.path.join(self.temprepos, self.repo_name)

        testing.mkdir(self.temprepo)

        os.chdir(self.tempdir)

        testing.system('cd %s && git init' % self.temprepo)
        testing.write(self.temprepo, 'test.txt', 'TEST')
        testing.system('cd %s && git add test.txt && git commit -m "Init"' % self.temprepo)
        testing.write(self.temprepo, 'test2.txt', 'TEST')
        submodule_path = os.path.join(self.temprepo, 'submodule_repo')
        testing.system('mkdir -p %s && cd %s && git init && echo 1 > file && git add file && git commit -m file' % (submodule_path, submodule_path))
        self.assertTrue(os.path.exists(os.path.join(submodule_path, '.git')))
        testing.system('cd %s && git submodule add %s submodule && git add .gitmodules && git commit -m submodule' % (self.temprepo, submodule_path))
        self.assertTrue(os.path.exists(os.path.join(self.temprepo, '.gitmodules')))
        testing.system('cd %s && git checkout -b test && git add test2.txt && git commit -m "Test-branch" && git checkout master' % self.temprepo)
Exemplo n.º 28
0
def create_celery_egg(test):
    """Create a dummy celery egg for testing.
       The included scripts simply print the content of the celeryconfig
       module.
    """
    from zc.buildout.testing import write
    dest = test.globs['sample_eggs']
    tmp = tempfile.mkdtemp()
    try:
        write(tmp, 'README.txt', '')
        write(
            tmp, 'celery.py', 'import celeryconfig\n'
            'def main():\n'
            ' print "\\n".join(["%s=%s" % (opt, repr(getattr(celeryconfig, '
            'opt))) for opt in dir(celeryconfig) if opt[0].isalpha()])\n')
        write(
            tmp, 'setup.py', "from setuptools import setup\n"
            "setup(name='celery', py_modules=['celery'],"
            " entry_points={'console_scripts': ['celeryd = celery:main', "
            "'celeryctl = celery:main']},"
            " zip_safe=True, version='2.3.1')\n")
        bdist_egg(tmp, sys.executable, dest)
        # Create another celery egg with a different version for testing
        # updating the celery egg.
        write(tmp, 'README.txt', '')
        write(
            tmp, 'celery.py', 'import celeryconfig\n'
            'def main():\n'
            ' print "\\n".join(["%s=%s" % (opt, repr(getattr(celeryconfig, '
            'opt))) for opt in dir(celeryconfig) if opt[0].isalpha()])\n')
        write(
            tmp, 'setup.py', "from setuptools import setup\n"
            "setup(name='celery', py_modules=['celery'],"
            " entry_points={'console_scripts': ['celeryd = celery:main', "
            "'celeryctl = celery:main']},"
            " zip_safe=True, version='2.3.0')\n")
        bdist_egg(tmp, sys.executable, dest)

    finally:
        shutil.rmtree(tmp)
Exemplo n.º 29
0
    def test__write_project_file(self):
        """ """
        from ..recipes import Recipe
        from ..recipes import default_st3_folders_settings

        buildout = self.buildout
        recipe_options = self.recipe_options.copy()
        del recipe_options['overwrite']
        recipe_options.update({
            'sublimelinter-enabled': 'True',
            'sublimelinter-flake8-enabled': 'True',
        })

        _project_file = 'human_project.sublime-project'

        write(
            self.location,
            _project_file,
            """{
                /*
                 This is comment.
                */
                "tests": {
                    "hello": 1
                },
                "settings": {
                    "SublimeLinter.linters.flake8.disable": true,
                    "SublimeLinter.linters.flake8.args": ["--max-complexity=10"]
                }

            }""",
        )

        buildout['sublimetext'] = recipe_options

        recipe = Recipe(buildout, 'sublimetext', buildout['sublimetext'])
        recipe._set_defaults()

        test_eggs_locations = [
            '/tmp/eggs/egg1.egg',
            '/tmp/eggs/egg2.egg',
        ]

        develop_eggs_locations = []

        st3_settings = recipe._prepare_settings(
            test_eggs_locations,
            develop_eggs_locations,
        )
        recipe._write_project_file(
            os.path.join(self.location, _project_file),
            st3_settings,
            False,
        )
        # By default no overwrite configuration, means existing configuration should be
        # available
        generated_settings = json.loads(
            read(os.path.join(self.location, _project_file)))

        # Test:: merged works with new and existing

        # Make sure value changed from buildout
        self.assertFalse(generated_settings['settings']
                         ['SublimeLinter.linters.flake8.disable'])
        # Make sure other value kept intact, because that option is not handled by this recipe
        self.assertEqual(
            generated_settings['settings']
            ['SublimeLinter.linters.flake8.args'], ['--max-complexity=10'])
        # Test:: default folders option is added, because existing file don't have this
        self.assertEqual(
            generated_settings['folders'],
            default_st3_folders_settings,
        )

        # Test: existing configuration is kept intact
        self.assertEqual(generated_settings['tests']['hello'], 1)

        buildout['sublimetext'].update({
            'sublimelinter-enabled': 'True',
            'sublimelinter-flake8-enabled': 'False',
            'sublimelinter-pylint-enabled': 'True',
            'jedi-enabled': 'True',
        })

        recipe = Recipe(buildout, 'sublimetext', buildout['sublimetext'])
        st3_settings = recipe._prepare_settings(
            test_eggs_locations,
            develop_eggs_locations,
        )

        recipe._write_project_file(
            os.path.join(self.location, _project_file),
            st3_settings,
            False,
        )

        generated_settings = json.loads(
            read(os.path.join(self.location, _project_file)))

        self.assertEqual(
            test_eggs_locations,
            generated_settings['settings']['python_package_paths'])
        # Test paths are added for `pylint`
        self.assertEqual(
            2,
            len(generated_settings['settings']
                ['SublimeLinter.linters.pylint.paths']))

        # Test: overwrite works!
        recipe._write_project_file(
            os.path.join(self.location, _project_file),
            st3_settings,
            True,
        )
        generated_settings = json.loads(
            read(os.path.join(self.location, _project_file)))
        self.assertNotIn('tests', generated_settings)
        # Test:: default folders setting
        # As completly overwrite file, so there is no folders option, so should have default
        self.assertEqual(
            generated_settings['folders'],
            default_st3_folders_settings,
        )

        # Test: Anaconda Settings is working

        buildout['sublimetext'].update({
            'anaconda-enabled': 'True',
            'anaconda-pep8-ignores': 'N802 W291',
        })

        recipe = Recipe(buildout, 'sublimetext', buildout['sublimetext'])
        st3_settings = recipe._prepare_settings(
            test_eggs_locations,
            develop_eggs_locations,
        )

        recipe._write_project_file(
            os.path.join(self.location, _project_file),
            st3_settings,
            True,
        )

        generated_settings = json.loads(
            read(os.path.join(self.location, _project_file)))
        self.assertIn('build_systems', generated_settings)
        self.assertEqual(generated_settings['build_systems'][0]['name'],
                         'PRS:: Anaconda Python Builder')
        # By default pylint disabled
        self.assertFalse(generated_settings['settings']['use_pylint'])
        # Should have two eggs paths in `extra_paths`
        self.assertEqual(len(generated_settings['settings']['extra_paths']), 2)
Exemplo n.º 30
0
    def test_install(self):
        """"""
        from ..recipes import Recipe

        buildout = self.buildout
        recipe_options = self.recipe_options.copy()
        recipe_options.update({
            'jedi-enabled': '1',
            'sublimelinter-enabled': '1',
            'sublimelinter-pylint-enabled': 'True',
            'anaconda-enabled': 'True',
        })
        buildout['sublimetext'] = recipe_options
        recipe = Recipe(buildout, 'sublimetext', buildout['sublimetext'])
        recipe.install()

        generated_settings = json.loads(
            read(
                os.path.join(
                    self.location,
                    recipe_options['project-name'] + '.sublime-project')), )
        # should be three, zc.buildout, zc,recipe.egg, python site-package path
        self.assertEqual(
            3, len(generated_settings['settings']['python_package_paths']))
        self.assertEqual(3, len(generated_settings['settings']['extra_paths']))
        self.assertIsInstance(
            generated_settings['settings']['python_interpreter'], str_)
        self.assertIn(
            recipe.buildout['buildout']['directory'] + '/bin/python',
            generated_settings['build_systems'][0]['shell_cmd'],
        )

        # Test with custom location with package
        buildout['sublimetext'].update({
            'packages':
            '/fake/path',
            'location':
            os.path.join(tempfile.gettempdir(), 'hshdshgdrts'),
        })

        recipe = Recipe(buildout, 'sublimetext', buildout['sublimetext'])
        recipe.install()

        generated_settings = json.loads(
            read(
                os.path.join(
                    buildout['sublimetext']['location'],
                    recipe_options['project-name'] + '.sublime-project',
                )), )

        # Now should four links
        self.assertEqual(
            4, len(generated_settings['settings']['python_package_paths']))

        # Make sure settings file is created at custom location
        self.assertTrue(
            os.path.exists(
                os.path.join(
                    buildout['sublimetext']['location'],
                    buildout['sublimetext']['project-name'] +
                    '.sublime-project',
                )))

        # restore
        rmtree.rmtree(buildout['sublimetext']['location'])
        del buildout['sublimetext']['location']
        del buildout['sublimetext']['packages']

        # Test ignores
        buildout['buildout'].update({
            'develop': '.',
        })
        buildout['sublimetext'].update({
            'ignores': 'zc.buildout',
            'ignore-develop': 'True',
        })
        recipe = Recipe(buildout, 'sublimetext', buildout['sublimetext'])
        recipe.install()

        generated_settings = json.loads(
            read(
                os.path.join(
                    self.location,
                    recipe_options['project-name'] + '.sublime-project')), )

        # should be two, zc.buildout is ignored
        self.assertEqual(
            2, len(generated_settings['settings']['python_package_paths']))

        # Failed Test: existing project file with invalid json
        write(
            self.location,
            recipe_options['project-name'] + '.sublime-project',
            """I am invalid""",
        )
        try:
            recipe.update()
            raise AssertionError(
                'Code should not come here, as invalid json inside existing project'
                'file! ValueError raised by UserError', )
        except UserError:
            pass

        # Failed Test: exception rasied by zc.recipe.Egg
        recipe.options.update({
            # Invalid Egg
            'eggs': '\\',
        })
        try:
            recipe.install()
            raise AssertionError(
                'Code should not come here, as should raised execption because of invalied eggs'
            )
        except UserError:
            pass
    def test_install(self):
        """"""
        from ..recipes import Recipe
        from ..recipes import mappings

        buildout = self.buildout
        recipe_options = self.recipe_options.copy()
        recipe_options.update(
            {
                "black-enabled": "1",
                "black-args": "--line-length 88",
                "black-path": "$project_path/bin/black",
                "flake8-enabled": "True",
                "flake8-args": "--max-line-length 88",
                "flake8-path": "${buildout:directory}/bin/flake8",
                "isort-enabled": "True",
                "isort-path": "${buildout:directory}/bin/isort",
                "generate-envfile": "True",
            }
        )
        buildout["vscode"] = recipe_options
        recipe = Recipe(buildout, "vscode", buildout["vscode"])
        recipe.install()

        generated_settings = json.loads(
            read(os.path.join(self.location, ".vscode", "settings.json"))
        )
        # should be two, zc,recipe.egg, python site-package path
        self.assertEqual(
            2, len(generated_settings[mappings["autocomplete-extrapaths"]])
        )
        self.assertEqual(
            generated_settings[mappings["flake8-path"]], self.location + "/bin/flake8"
        )

        # Isort executable should get automatically
        self.assertEqual(
            generated_settings[mappings["isort-path"]],
            self.location + "/bin/isort"
        )

        # Test existence and configuration of env file
        envfile_path = os.path.join(self.location, ".vscode", ".env")
        self.assertEqual(generated_settings["python.envFile"], envfile_path)
        self.assertTrue(os.path.isfile(envfile_path))

        # Test with custom location with package
        buildout["vscode"].update({
            "packages": "/fake/path",
            "project-root": os.path.join(tempfile.gettempdir(), "hshdshgdrts"),
        })

        recipe = Recipe(buildout, "vscode", buildout["vscode"])
        recipe.install()

        generated_settings = json.loads(
            read(
                os.path.join(
                    buildout["vscode"]["project-root"], ".vscode", "settings.json"
                )
            )
        )

        # Now should three (two+one) links
        self.assertEqual(
            3, len(generated_settings[mappings["autocomplete-extrapaths"]])
        )

        # restore
        rmtree.rmtree(buildout["vscode"]["project-root"])
        del buildout["vscode"]["project-root"]
        del buildout["vscode"]["packages"]

        # Test ignores
        buildout["buildout"].update({"develop": "."})
        buildout["vscode"].update({"ignores": "zc.buildout", "ignore-develop": "True"})
        recipe = Recipe(buildout, "vscode", buildout["vscode"])
        recipe.install()

        generated_settings = json.loads(
            read(os.path.join(self.location, ".vscode", "settings.json"))
        )

        # should be two, zc.buildout is ignored
        self.assertEqual(
            2, len(generated_settings[mappings["autocomplete-extrapaths"]])
        )

        # Failed Test: existing project file with invalid json
        write(
            os.path.join(self.location, ".vscode"), "settings.json", """I am invalid"""
        )
        try:
            recipe.update()
            raise AssertionError(
                "Code should not come here, as invalid json inside existing project"
                "file! ValueError raised by UserError"
            )
        except UserError:
            pass

        # Failed Test: exception rasied by zc.recipe.Egg
        recipe.options.update(
            {
                # Invalid Egg
                "eggs": "\\"
            }
        )
        try:
            recipe.install()
            raise AssertionError(
                "Code should not come here, as should raised execption "
                "because of invalid eggs"
            )
        except UserError:
            pass