<commit_before><commit_msg>add key server cmd line arg parser unit tests<commit_after>"""This module implements a collection of unit tests for
the Key Server's key_server.clparser.CommandLineParser."""

import logging
import unittest

from yar.key_server.clparser import CommandLineParser


class CommandLineParserUnitTase(unittest.TestCase):
    """A collection of unit tests for the Key Server's
    key_server.clparser.CommandLineParser."""

    def test_defaults(self):
        """Verify the command line parser supplies the
        expected defaults when not command line arguments
        are supplied."""
        args = []

        clp = CommandLineParser()
        (clo, cla) = clp.parse_args(args)

        self.assertEqual(clo.logging_level, logging.ERROR)
        self.assertEqual(clo.listen_on, [("127.0.0.1", 8070)])
        self.assertEqual(clo.key_store, "127.0.0.1:5984/creds")
        self.assertIsNone(clo.logging_file)
        self.assertIsNone(clo.syslog)

    def test_logging_level(self):
        """Verify the command line parser correctly parses
        the --log command line arg."""
        args = [
            "--log", "info",
        ]

        clp = CommandLineParser()
        (clo, cla) = clp.parse_args(args)

        self.assertEqual(clo.logging_level, logging.INFO)
        self.assertEqual(clo.listen_on, [("127.0.0.1", 8070)])
        self.assertEqual(clo.key_store, "127.0.0.1:5984/creds")
        self.assertIsNone(clo.logging_file)
        self.assertIsNone(clo.syslog)

    def test_listen_on(self):
        """Verify the command line parser correctly parses
        the --lon command line arg."""
        args = [
            "--lon", "1.1.1.1:7878",
        ]

        clp = CommandLineParser()
        (clo, cla) = clp.parse_args(args)

        self.assertEqual(clo.logging_level, logging.ERROR)
        self.assertEqual(clo.listen_on, [("1.1.1.1", 7878)])
        self.assertEqual(clo.key_store, "127.0.0.1:5984/creds")
        self.assertIsNone(clo.logging_file)
        self.assertIsNone(clo.syslog)

    def test_key_store(self):
        """Verify the command line parser correctly parses
        the --keystore command line arg."""
        args = [
            "--key_store", "1.1.1.1:7878/bindle",
        ]

        clp = CommandLineParser()
        (clo, cla) = clp.parse_args(args)

        self.assertEqual(clo.logging_level, logging.ERROR)
        self.assertEqual(clo.listen_on, [("127.0.0.1", 8070)])
        self.assertEqual(clo.key_store, args[-1])
        self.assertIsNone(clo.logging_file)
        self.assertIsNone(clo.syslog)

    def test_syslog(self):
        """Verify the command line parser correctly parses
        the --keystore command line arg."""
        args = [
            "--syslog", "/dave/was/here",
        ]

        clp = CommandLineParser()
        (clo, cla) = clp.parse_args(args)

        self.assertEqual(clo.logging_level, logging.ERROR)
        self.assertEqual(clo.listen_on, [("127.0.0.1", 8070)])
        self.assertEqual(clo.key_store, "127.0.0.1:5984/creds")
        self.assertIsNone(clo.logging_file)
        self.assertEqual(clo.syslog, args[-1])

    def test_logging_file(self):
        """Verify the command line parser correctly parses
        the --keystore command line arg."""
        args = [
            "--logfile", "/dave/was/here.log",
        ]

        clp = CommandLineParser()
        (clo, cla) = clp.parse_args(args)

        self.assertEqual(clo.logging_level, logging.ERROR)
        self.assertEqual(clo.listen_on, [("127.0.0.1", 8070)])
        self.assertEqual(clo.key_store, "127.0.0.1:5984/creds")
        self.assertEqual(clo.logging_file, args[-1])
        self.assertIsNone(clo.syslog)
{'fraction_non_alphanumeric': 0.13099730458221023, 'fraction_numerical': 0.03423180592991914, 'mean_word_length': 2.487781954887218, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 13, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2969163', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1163, 'n_words': 231}