def test_pyfile_defaults_settings(self):
        """ """
        from ..recipes import python_file_defaults
        from ..recipes import Recipe

        recipe_options = self.recipe_options.copy()
        self.buildout["vscode"] = recipe_options

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

        generated_settings = json.loads(
            read(os.path.join(self.location, ".vscode", "settings.json"))
        )
        for key in python_file_defaults:
            self.assertIn(key, generated_settings)

        with open(os.path.join(self.location, ".vscode", "settings.json"), "w") as fp:
            json.dump({"files.associations": {}, "files.exclude": []}, fp)

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

        generated_settings = json.loads(
            read(os.path.join(self.location, ".vscode", "settings.json"))
        )
        for key in python_file_defaults:
            self.assertNotEqual(python_file_defaults[key], generated_settings[key])
예제 #2
0
    def test_install_autoeggs(self):
        """"""
        from ..recipes import Recipe
        from ..recipes import mappings

        buildout = self.buildout
        recipe_options = self.recipe_options.copy()
        del recipe_options["eggs"]

        buildout["test"] = {
            "recipe": "zc.recipe.egg",
            "eggs": "zc.buildout",
            "dependent-scripts": "false",
        }
        buildout["test"].recipe = zc.recipe.egg.Egg(buildout, "test",
                                                    buildout["test"])

        buildout["buildout"]["parts"] = "test vscode"
        buildout["vscode"] = recipe_options
        buildout["vscode"].recipe = Recipe(buildout, "vscode",
                                           buildout["vscode"])

        self.buildout.install(None)

        generated_settings = json.loads(
            read(os.path.join(self.location, ".vscode", "settings.json")))
        # TODO: should be two, zc,recipe.egg, python site-package path
        self.assertEqual(
            ["site-packages"],
            [
                p.split("/")[-1] for p in generated_settings[
                    mappings["autocomplete-extrapaths"]]
            ],
        )
예제 #3
0
    def test_sublimelinter_linter_settings(self):
        """ """
        from ..recipes import Recipe

        buildout = self.buildout
        recipe_options = self.recipe_options.copy()
        recipe_options.update({
            'sublimelinter-enabled':
            '1',
            'sublimelinter-pylint-enabled':
            'True',
            'sublimelinter-pylint-args':
            'disable=all ',
            'sublimelinter-flake8-enabled':
            '1',
            'sublimelinter-flake8-args':
            'max-complexity=10  max-line-length=119\n'
            '   exclude=docs,*.egg.,omelette',
        })
        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
        self.assertEqual(
            3,
            len(generated_settings['settings']
                ['SublimeLinter.linters.flake8.args']))
        # make sure -- prefix is added
        self.assertEqual(
            generated_settings['settings']
            ['SublimeLinter.linters.flake8.args'], [
                '--max-complexity=10', '--max-line-length=119',
                '--exclude=docs,*.egg.,omelette'
            ])

        self.assertEqual(
            1,
            len(generated_settings['settings']
                ['SublimeLinter.linters.pylint.args']))
예제 #4
0
    def test_anaconda_pep257(self):
        """ """
        from ..recipes import Recipe

        buildout = self.buildout
        recipe_options = self.recipe_options.copy()
        recipe_options.update({
            'anaconda-enabled': '1',
            'anaconda-pep257-enabled': 'True',
            'anaconda-pep257-ignores': 'M001 K001\nL001',
        })
        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
        self.assertTrue(generated_settings['settings']['pep257'])
        self.assertEqual(3,
                         len(generated_settings['settings']['pep257_ignore']))
    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
    def test_issue2(self):
        """Issue:2 Linter disabling simply not working"""
        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",
                "pylint-enabled": "False",
            }
        )
        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 have an entry of pylint
        self.assertIn(mappings["pylint-enabled"], generated_settings)
        self.assertFalse(generated_settings[mappings["pylint-enabled"]])

        buildout["vscode"]["pylint-enabled"] = "True"
        recipe = Recipe(buildout, "vscode", buildout["vscode"])
        recipe.install()

        generated_settings = json.loads(
            read(os.path.join(self.location, ".vscode", "settings.json"))
        )
        # should enable now
        self.assertTrue(generated_settings[mappings["pylint-enabled"]])

        del recipe_options["black-enabled"]
        del recipe_options["black-path"]
        del recipe_options["flake8-enabled"]
        recipe_options["isort-enabled"] = "False"

        buildout["vscode2"] = recipe_options

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

        generated_settings = json.loads(
            read(os.path.join(self.location, ".vscode", "settings.json"))
        )
        # flake8 enable flag should not exists

        self.assertNotIn(mappings["flake8-enabled"], generated_settings)
        # same for black
        self.assertNotIn(mappings["formatting-provider"], generated_settings)

        # still flake8 path should exists
        self.assertIn(mappings["flake8-path"], generated_settings)
        # But not blackpath
        self.assertNotIn(mappings["black-path"], generated_settings)

        # there should no auto isort executable
        self.assertNotIn(mappings["isort-path"], generated_settings)
    def test__write_project_file(self):
        """ """
        from ..recipes import mappings
        from ..recipes import Recipe

        buildout = self.buildout
        recipe_options = self.recipe_options.copy()
        buildout["vscode"] = recipe_options

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

        recipe_options["jedi-enabled"] = "True"
        recipe_options["pylint-enabled"] = "True"
        recipe_options["flake8-enabled"] = "True"
        recipe_options["flake8-path"] = "/fake/path/flake8"
        recipe_options["black-enabled"] = "True"
        recipe_options["black-path"] = "/tmp/bin/black"
        recipe_options["black-args"] = "--line-length\n88"

        buildout["vscode"].update(recipe_options)

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

        vsc_settings = recipe._prepare_settings(
            test_eggs_locations, develop_eggs_locations, {}
        )
        recipe._write_project_file(vsc_settings, {})
        # By default no overwrite configuration, means existing configuration should be
        # available
        generated_settings = json.loads(
            read(os.path.join(self.location, ".vscode", "settings.json"))
        )

        # Make sure other value kept intact, because that option is not handled by
        # this recipe.
        self.assertEqual(
            generated_settings[mappings["flake8-path"]], "/fake/path/flake8"
        )
        # Test:: default folders option is added, because existing file don't have this
        self.assertEqual(
            generated_settings[mappings["black-args"]], ["--line-length", "88"]
        )

        buildout["vscode"].update(
            {"black-enabled": "False", "flake8-path": "/new/path/flake8"}
        )

        recipe = Recipe(buildout, "vscode", buildout["vscode"])
        vsc_settings2 = recipe._prepare_settings(
            test_eggs_locations, develop_eggs_locations, vsc_settings
        )

        recipe._write_project_file(vsc_settings2, vsc_settings)

        generated_settings = json.loads(
            read(os.path.join(self.location, ".vscode", "settings.json"))
        )
        # there should not any formatting provider
        self.assertNotIn(mappings["formatting-provider"], generated_settings)
        # Black path still exists
        self.assertIn(mappings["black-path"], generated_settings)
        # Test: overwrite works!
        self.assertEqual(
            generated_settings[mappings["flake8-path"]], "/new/path/flake8"
        )
예제 #8
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
예제 #9
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)