def test_supplied_feature_file(self):
        config = Mock()
        config.paths = ['features/group1/foo.feature']
        config.verbose = True
        r = runner.Runner(config)
        r.context = Mock()

        fs = FsMock(
            'features/',
            'features/group1/',
            'features/group1/foo.feature',
            'features/steps/',
        )

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                with r.path_manager:
                    r.setup_paths()

        features_path = os.path.join(fs.base, 'features')
        ok_(
            ('isdir',  os.path.join(features_path, 'steps'))
            in fs.calls
        )
        ok_(
            ('isfile', os.path.join(features_path, 'group1', 'foo.feature'))
            in fs.calls
        )
        eq_(r.base_dir, fs.join(fs.base, "features"))
Beispiel #2
0
 def test_csv_header(self):
     options_mock = Mock()
     options_mock.verbose = True
     options_mock.extensions = []
     csv_output(AllResult([self.fileSummary]), options_mock)
     self.assertRegexpMatches(sys.stdout.stream,
                              r"NLOC,CCN,token,PARAM,length,location,file,function,long_name,start,end")
Beispiel #3
0
 def test_csv_no_header(self):
     options_mock = Mock()
     options_mock.verbose = False
     options_mock.extensions = []
     csv_output(AllResult([self.fileSummary]), options_mock)
     self.assertEqual(
         '1,1,1,0,0,"foo@100-100@FILENAME","FILENAME","foo","foo",100,100',
         sys.stdout.stream.splitlines()[0])
Beispiel #4
0
def io_logger():
    io = StringIO()
    args = Mock()
    args.verbose = 2
    assert args.verbose == 2
    handler, = setup_logging(args, io)
    handler.setFormatter(logging.Formatter('%(name)s: %(message)s'))
    logger.setLevel(logging.DEBUG)
    return io
 def test_extendparser(self, exit_mock):
     be = self._make_one()
     parser = Mock()
     arg_ret = Mock()
     parser.parse_args = Mock(return_value=(arg_ret, None))
     arg_ret.verbose = 1
     arg_ret.quiet = 1
     assert be.extend_parser(parser) is None
     assert exit_mock.call_args[0][0] == 0
Beispiel #6
0
def io_logger():
    io = StringIO()
    args = Mock()
    args.verbose = 2
    assert args.verbose == 2
    handler, = setup_logging(args, io)
    handler.setFormatter(logging.Formatter("%(name)s: %(message)s"))
    logger.setLevel(logging.DEBUG)
    return io
Beispiel #7
0
 def test_extendparser(self, exit_mock):
     be = self._make_one()
     parser = Mock()
     arg_ret = Mock()
     parser.parse_args = Mock(return_value=(arg_ret, None))
     arg_ret.verbose = 1
     arg_ret.quiet = 1
     assert be.extend_parser(parser) is None
     assert exit_mock.call_args[0][0] == 0
Beispiel #8
0
    def test_default_path_no_features(self):
        config = Mock()
        config.paths = []
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock('features/steps/')
        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                assert_raises(ConfigError, r.setup_paths)
Beispiel #9
0
    def test_default_path_no_features(self):
        config = Mock()
        config.paths = []
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock("features/steps/")
        with patch("os.path", fs):
            with patch("os.walk", fs.walk):
                assert_raises(ConfigError, r.setup_paths)
Beispiel #10
0
    def test_supplied_feature_directory_missing(self):
        config = Mock()
        config.paths = ['spam']
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock()

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                assert_raises(ConfigError, r.setup_paths)
Beispiel #11
0
    def test_supplied_feature_directory_missing(self):
        config = Mock()
        config.paths = ["spam"]
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock()

        with patch("os.path", fs):
            with patch("os.walk", fs.walk):
                assert_raises(ConfigError, r.setup_paths)
Beispiel #12
0
    def test_default_path_no_features(self):
        config = Mock()
        config.paths = []
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock('features/steps/')
        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                # pylint: disable=E0602
                #   E0602   Undefined variable "assert_raises"
                assert_raises(ConfigError, r.setup_paths)
Beispiel #13
0
    def test_supplied_feature_file_no_steps(self):
        config = Mock()
        config.paths = ['foo.feature']
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock('foo.feature')

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                with r.path_manager:
                    assert_raises(ConfigError, r.setup_paths)
Beispiel #14
0
    def test_supplied_feature_file_no_steps(self):
        config = Mock()
        config.paths = ['foo.feature']
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock('foo.feature')

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                with r.path_manager:
                    assert_raises(ConfigError, r.setup_paths)
Beispiel #15
0
    def test_supplied_feature_file_no_steps(self):
        config = Mock()
        config.paths = ["features/group1/foo.feature"]
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock("features/", "features/group1/", "features/group1/foo.feature")

        with patch("os.path", fs):
            with patch("os.walk", fs.walk):
                with r.path_manager:
                    assert_raises(ConfigError, r.setup_paths)
Beispiel #16
0
 def test_csv_header_with_extension(self):
     options_mock = Mock()
     options_mock.verbose = True
     extension_mock = Mock()
     extension_mock.__class__.__name__ = 'LizardExtension'
     extension_mock.FUNCTION_INFO = {"exit_count": {"caption": "exits"}}
     options_mock.extensions = [extension_mock]
     results = AllResult([self.fileSummary])
     results.result[0].function_list[0].exit_count = 1
     csv_output(results, options_mock)
     self.assertRegexpMatches(sys.stdout.stream,
                              r"NLOC,CCN,token,PARAM,length,location,file,function,long_name,start,end,exits")
Beispiel #17
0
    def test_default_path_no_steps(self):
        config = Mock()
        config.paths = []
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock()

        # will look for a "features" directory and not find one
        with patch('os.path', fs):
            assert_raises(ConfigError, r.setup_paths)

        ok_(('isdir', os.path.join(fs.base, 'features', 'steps')) in fs.calls)
Beispiel #18
0
    def test_supplied_feature_directory_no_steps(self):
        config = Mock()
        config.paths = ["features/group1"]
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock("features/", "features/group1/", "features/group1/foo.feature")

        with patch("os.path", fs):
            with patch("os.walk", fs.walk):
                assert_raises(ConfigError, r.setup_paths)

        ok_(("isdir", os.path.join(fs.base, "features", "steps")) in fs.calls)
Beispiel #19
0
    def test_supplied_feature_directory_no_steps(self):
        config = Mock()
        config.paths = ['spam']
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock('spam/', 'spam/foo.feature')

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                assert_raises(ConfigError, r.setup_paths)

        ok_(('isdir', os.path.join(fs.base, 'spam', 'steps')) in fs.calls)
Beispiel #20
0
    def test_default_path_no_steps(self):
        config = Mock()
        config.paths = []
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock()

        # will look for a "features" directory and not find one
        with patch("os.path", fs):
            assert_raises(ConfigError, r.setup_paths)

        ok_(("isdir", os.path.join(fs.base, "features", "steps")) in fs.calls)
Beispiel #21
0
    def test_supplied_feature_directory_missing(self):
        config = Mock()
        config.paths = ['spam']
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock()

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                # pylint: disable=E0602
                #   E0602   Undefined variable "assert_raises"
                assert_raises(ConfigError, r.setup_paths)
Beispiel #22
0
    def test_supplied_feature_directory_no_steps(self):
        config = Mock()
        config.paths = ['spam']
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock('spam/', 'spam/foo.feature')

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                assert_raises(ConfigError, r.setup_paths)

        ok_(('isdir', os.path.join(fs.base, 'spam', 'steps')) in fs.calls)
Beispiel #23
0
    def test_print_extension(self):
        options_mock = Mock()
        options_mock.verbose = True
        options_mock.extensions = []

        self.foo.end_line = 100
        self.foo.cyclomatic_complexity = 16
        fileStat = FileInformation("FILENAME", 1, [self.foo])

        csv_output(AllResult([fileStat]), options_mock)

        self.assertEqual(
            '1,16,1,0,0,"foo@100-100@FILENAME","FILENAME","foo","foo",100,100',
            sys.stdout.stream.splitlines()[1])
Beispiel #24
0
    def test_default_path(self):
        config = Mock()
        config.paths = []
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock("features/", "features/steps/", "features/group1/", "features/group1/foo.feature")

        with patch("os.path", fs):
            with patch("os.walk", fs.walk):
                with r.path_manager:
                    r.setup_paths()

        eq_(r.base_dir, os.path.abspath("features"))
Beispiel #25
0
    def test_default_path(self):
        config = Mock()
        config.paths = []
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock('features/steps/', 'features/foo.feature')

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                with r.path_manager:
                    r.setup_paths()

        eq_(r.base_dir, os.path.abspath('features'))
Beispiel #26
0
    def test_default_path(self):
        config = Mock()
        config.paths = []
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock('features/steps/', 'features/foo.feature')

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                with r.path_manager:
                    r.setup_paths()

        eq_(r.base_dir, os.path.abspath('features'))
Beispiel #27
0
    def test_default_path_no_steps(self):
        config = Mock()
        config.paths = []
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock()

        # will look for a "features" directory and not find one
        with patch('os.path', fs):
            # pylint: disable=E0602
            #   E0602   Undefined variable "assert_raises"
            assert_raises(ConfigError, r.setup_paths)

        ok_(('isdir', os.path.join(fs.base, 'features', 'steps')) in fs.calls)
Beispiel #28
0
    def test_supplied_feature_directory(self):
        config = Mock()
        config.paths = ["features/group1"]
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock("features/", "features/group1/", "features/group1/foo.feature", "features/steps/")

        with patch("os.path", fs):
            with patch("os.walk", fs.walk):
                with r.path_manager:
                    r.setup_paths()

        ok_(("isdir", os.path.join(fs.base, "features", "steps")) in fs.calls)
        eq_(r.base_dir, os.path.join(fs.base, "features"))
Beispiel #29
0
    def test_csv_no_header_with_extension(self):
        options_mock = Mock()
        options_mock.verbose = False
        options_mock.extensions = []
        extension_mock = Mock()
        extension_mock.__class__.__name__ = 'LizardExtension'
        extension_mock.FUNCTION_INFO = {"exit_count": {"caption": "exits"}}
        options_mock.extensions = [extension_mock]

        results = AllResult([self.fileSummary])
        results.result[0].function_list[0].exit_count = 1
        csv_output(results, options_mock)

        self.assertEqual(
            '1,1,1,0,0,"foo@100-100@FILENAME","FILENAME","foo","foo",100,100,1',
            sys.stdout.stream.splitlines()[0])
Beispiel #30
0
    def test_supplied_feature_directory(self):
        config = Mock()
        config.paths = ['spam']
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock('spam/', 'spam/steps/', 'spam/foo.feature')

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                with r.path_manager:
                    r.setup_paths()

        ok_(('isdir', os.path.join(fs.base, 'spam', 'steps')) in fs.calls)

        eq_(r.base_dir, os.path.join(fs.base, 'spam'))
Beispiel #31
0
    def test_supplied_feature_directory(self):
        config = Mock()
        config.paths = ['spam']
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock('spam/', 'spam/steps/', 'spam/foo.feature')

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                with r.path_manager:
                    r.setup_paths()

        ok_(('isdir', os.path.join(fs.base, 'spam', 'steps')) in fs.calls)

        eq_(r.base_dir, os.path.join(fs.base, 'spam'))
Beispiel #32
0
    def test_supplied_feature_file(self):
        config = Mock()
        config.paths = ["foo.feature"]
        config.verbose = True
        r = runner.Runner(config)
        r.context = Mock()

        fs = FsMock("steps/", "foo.feature")

        with patch("os.path", fs):
            with patch("os.walk", fs.walk):
                with r.path_manager:
                    r.setup_paths()
        ok_(("isdir", os.path.join(fs.base, "steps")) in fs.calls)
        ok_(("isfile", os.path.join(fs.base, "foo.feature")) in fs.calls)

        eq_(r.base_dir, fs.base)
Beispiel #33
0
  def testContentsCommand(self):
    file_list = ['foo', 'bar']

    options = Mock(verbose=False, all=False)
    package = Mock(NAME='test', Files=Mock(return_value=file_list))

    expected_output = '\n'.join(file_list) + '\n'
    with patch('sys.stdout', new_callable=StringIO.StringIO) as stdout:
      naclports.__main__.CmdPkgContents(package, options)
      self.assertEqual(stdout.getvalue(), expected_output)

    # when the verbose option is set expect CmdContents to output full paths.
    options.verbose = True
    expected_output = [os.path.join('/package/install/path', f)
                       for f in file_list]
    expected_output = '\n'.join(expected_output) + '\n'
    with patch('sys.stdout', new_callable=StringIO.StringIO) as stdout:
      naclports.__main__.CmdPkgContents(package, options)
      self.assertEqual(stdout.getvalue(), expected_output)
Beispiel #34
0
    def test_supplied_root_directory_no_steps(self):
        config = Mock()
        config.paths = ['features']
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock(
            'features/',
            'features/group1/',
            'features/group1/foo.feature',
        )

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                with r.path_manager:
                    assert_raises(ConfigError, r.setup_paths)

        ok_(('isdir', os.path.join(fs.base, 'features', 'steps')) in fs.calls)
        eq_(r.base_dir, None)
Beispiel #35
0
    def test_supplied_root_directory_no_steps(self):
        config = Mock()
        config.paths = [ 'features' ]
        config.verbose = True
        r = runner.Runner(config)

        fs = FsMock(
            'features/',
            'features/group1/',
            'features/group1/foo.feature',
        )

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                with r.path_manager:
                    assert_raises(ConfigError, r.setup_paths)

        ok_(('isdir',  os.path.join(fs.base, 'features', 'steps')) in fs.calls)
        eq_(r.base_dir, None)
Beispiel #36
0
    def testContentsCommand(self):
        file_list = ['foo', 'bar']

        options = Mock(verbose=False, all=False)
        package = Mock(NAME='test', Files=Mock(return_value=file_list))

        expected_output = '\n'.join(file_list) + '\n'
        with patch('sys.stdout', new_callable=StringIO.StringIO) as stdout:
            naclports.__main__.CmdPkgContents(package, options)
            self.assertEqual(stdout.getvalue(), expected_output)

        # when the verbose option is set expect CmdContents to output full paths.
        options.verbose = True
        expected_output = [
            os.path.join('/package/install/path', f) for f in file_list
        ]
        expected_output = '\n'.join(expected_output) + '\n'
        with patch('sys.stdout', new_callable=StringIO.StringIO) as stdout:
            naclports.__main__.CmdPkgContents(package, options)
            self.assertEqual(stdout.getvalue(), expected_output)
Beispiel #37
0
    def test_supplied_feature_file(self):
        config = Mock()
        config.paths = [ 'features/group1/foo.feature' ]
        config.verbose = True
        r = runner.Runner(config)
        r.context = Mock()

        fs = FsMock(
            'features/',
            'features/group1/',
            'features/group1/foo.feature',
            'features/steps/',
        )

        with patch('os.path', fs):
            with patch('os.walk', fs.walk):
                with r.path_manager:
                    r.setup_paths()

        ok_(('isdir',  os.path.join(fs.base, 'features', 'steps'))  in fs.calls)
        ok_(('isfile', os.path.join(fs.base, 'features', 'group1', 'foo.feature')) in fs.calls)
        eq_(r.base_dir, fs.join(fs.base, "features"))
Beispiel #38
0
 def create_mock_config():
     mock_config = Mock()
     mock_config._check_version = MagicMock(return_value=None)
     mock_config.verbose = False