Ejemplo n.º 1
0
    def test_build_environment(self):
        cwd = Path('path', 'to', 'cwd')
        home = Path('/', 'home', 'user')
        xdg_config_home = Path('/', 'home', 'user', '.config')

        cmdargs = {
            'verbose': True,
            'warning': True,
            'max_violations': 10,
            'files': [str(FIXTURE_PATH)],
        }

        expected_env = {
            'cmdargs': {
                'files': [str(FIXTURE_PATH)],
                'verbose': True,
                'warning': True,
                'max_violations': 10,
            },
            'file_paths':
            set([
                Path(FIXTURE_PATH, '1.vim'),
                Path(FIXTURE_PATH, '2.vim'),
                Path(FIXTURE_PATH, 'sub', '3.vim'),
                Path(FIXTURE_PATH, 'sub', '4.vim'),
            ]),
            'home_path':
            home,
            'xdg_config_home':
            xdg_config_home,
            'cwd':
            cwd,
        }

        # we should mock os.getcwd() because env get the cwd by os.getcwd()
        with mock.patch('os.getcwd') as mocked_getcwd:
            mocked_getcwd.return_value = str(cwd)

            with mock.patch('os.path.expanduser') as mocked_expanduser:
                mocked_expanduser.return_value = str(home)

                with mock.patch.dict(
                        'os.environ',
                    {'XDG_CONFIG_HOME': '/home/user/.config'}):
                    env = build_environment(cmdargs)

        self.maxDiff = 1000
        self.assertEqual(env, expected_env)
Ejemplo n.º 2
0
    def assertExitWithFailure(self, argv):
        with mock.patch('sys.argv', argv):
            with self.assertRaises(SystemExit) as e:
                cli = CLI()
                cli.start()

            self.assertNotEqual(e.exception.code, 0)
Ejemplo n.º 3
0
    def assertExitWithFailure(self, argv):
        with mock.patch("sys.argv", argv):
            with self.assertRaises(SystemExit) as e:
                cli = CLI()
                cli.start()

            self.assertNotEqual(e.exception.code, 0)
Ejemplo n.º 4
0
    def test_build_environment(self):
        cwd = Path('path', 'to', 'cwd')
        home = Path('/', 'home', 'user')
        xdg_config_home = Path('/', 'home', 'user', '.config')

        cmdargs = {
            'verbose': True,
            'warning': True,
            'max_violations': 10,
            'files': [str(FIXTURE_PATH)],
        }

        expected_env = {
            'cmdargs': {
                'files': [str(FIXTURE_PATH)],
                'verbose': True,
                'warning': True,
                'max_violations': 10,
            },
            'file_paths': [
                Path(FIXTURE_PATH, '1.vim'),
                Path(FIXTURE_PATH, '2.vim'),
                Path(FIXTURE_PATH, 'sub', '3.vim'),
                Path(FIXTURE_PATH, 'sub', '4.vim'),
            ],
            'home_path': home,
            'xdg_config_home': xdg_config_home,
            'cwd': cwd,
        }

        # we should mock os.getcwd() because env get the cwd by os.getcwd()
        with mock.patch('os.getcwd') as mocked_getcwd:
            mocked_getcwd.return_value = str(cwd)

            with mock.patch('os.path.expanduser') as mocked_expanduser:
                mocked_expanduser.return_value = str(home)

                with mock.patch.dict('os.environ', {'XDG_CONFIG_HOME': '/home/user/.config'}):
                    env = build_environment(cmdargs)

        self.maxDiff = 1000
        self.assertEqual(env, expected_env)
Ejemplo n.º 5
0
    def assertExitWithFailure(self, argv):
        with mock.patch('sys.argv', argv):
            with self.assertRaises(SystemExit) as e:
                start_cli()

            self.assertNotEqual(e.exception.code, 0)
Ejemplo n.º 6
0
    def assertExitWithSuccess(self, argv):
        with mock.patch('sys.argv', argv):
            with self.assertRaises(SystemExit) as e:
                start_cli()

            self.assertEqual(e.exception.code, 0)