<commit_before>#!/usr/bin/python

# Copyright (C) 2015 <NAME>, <NAME> and <NAME>.
# Copyright (C) 2015 Research and Innovation Advanced Network New Zealand Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import os
import ipaddr

testdir = os.path.dirname(__file__)
srcdir = '../src/ryu_faucet/org/onfsdn/faucet'
sys.path.insert(0, os.path.abspath(os.path.join(testdir, srcdir)))

import unittest
from config_parser import dp_parser, watcher_parser

class DistConfigTestCase(unittest.TestCase):
    def setUp(self):
        self.v1_dp = dp_parser('config/testconfig.yaml', 'test_config')[0]
        self.v2_dp = dp_parser('config/testconfigv2.yaml', 'test_config')[0]
        self.v1_watchers = watcher_parser(
            'config/testgaugeconfig.conf', 'test_config')
        self.v2_watchers = watcher_parser(
            'config/testgaugeconfig.yaml', 'test_config')

    def test_dps(self):
        for dp in (self.v1_dp, self.v2_dp):
            # confirm that DPIDs match
            self.assertEqual(dp.dp_id, 0xcafef00d)

    def test_port_numbers(self):
        for dp in (self.v1_dp, self.v2_dp):
            # check the port numbers line up
            self.assertEqual(set(dp.ports.keys()), set([1, 2, 3, 4, 5, 6]))

    def test_ports_vlans(self):
        for dp in (self.v1_dp, self.v2_dp):
            # load ports for easy reading
            portcafef00d_1 = dp.ports[1]
            portcafef00d_2 = dp.ports[2]
            portcafef00d_3 = dp.ports[3]
            portcafef00d_4 = dp.ports[4]
            portcafef00d_5 = dp.ports[5]
            # check that the ports are in the right vlans
            self.assertIn(portcafef00d_1, dp.vlans[40].tagged)
            self.assertIn(portcafef00d_1, dp.vlans[41].tagged)
            self.assertIn(portcafef00d_2, dp.vlans[40].untagged)
            self.assertIn(portcafef00d_3, dp.vlans[40].untagged)
            self.assertIn(portcafef00d_3, dp.vlans[41].tagged)
            self.assertIn(portcafef00d_4, dp.vlans[41].untagged)
            self.assertIn(portcafef00d_5, dp.vlans[41].untagged)
            # check that the ports are not in vlans they should not be<commit_msg>Configure test_config logger to allow meaningful dp_parser error output<commit_after>#!/usr/bin/python

# Copyright (C) 2015 <NAME>, <NAME> and <NAME>.
# Copyright (C) 2015 Research and Innovation Advanced Network New Zealand Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import sys
import os
import ipaddr

testdir = os.path.dirname(__file__)
srcdir = '../src/ryu_faucet/org/onfsdn/faucet'
sys.path.insert(0, os.path.abspath(os.path.join(testdir, srcdir)))

import unittest
from config_parser import dp_parser, watcher_parser

class DistConfigTestCase(unittest.TestCase):
    def setUp(self):
        logname = 'test_config'

        logger = logging.getLogger("%s.config" % logname)
        logger_handler = logging.StreamHandler(stream=sys.stderr)
        log_fmt = '%(asctime)s %(name)-6s %(levelname)-8s %(message)s'
        logger_handler.setFormatter(
            logging.Formatter(log_fmt, '%b %d %H:%M:%S'))
        logger.addHandler(logger_handler)
        logger.propagate = 0
        logger.setLevel(logging.WARNING)

        self.v1_dp = dp_parser('config/testconfig.yaml', logname)[0]
        self.v2_dp = dp_parser('config/testconfigv2.yaml', logname)[0]
        self.v1_watchers = watcher_parser(
            'config/testgaugeconfig.conf', logname)
        self.v2_watchers = watcher_parser(
            'config/testgaugeconfig.yaml', logname)

    def test_dps(self):
        for dp in (self.v1_dp, self.v2_dp):
            # confirm that DPIDs match
            self.assertEqual(dp.dp_id, 0xcafef00d)

    def test_port_numbers(self):
        for dp in (self.v1_dp, self.v2_dp):
            # check the port numbers line up
            self.assertEqual(set(dp.ports.keys()), set([1, 2, 3, 4, 5, 6]))

    def test_ports_vlans(self):
        for dp in (self.v1_dp, self.v2_dp):
            # load ports for easy reading
            portcafef00d_1 = dp.ports[1]
            portcafef00d_2 = dp.ports[2]
            portcafef00d_3 = dp.ports[3]
            portcafef00d_4 = dp.ports[4]
            portcafef00d_5 = dp.ports[5]
            # check that the ports are in the right vlans
            self.assertIn(portcafef00d_1, dp.vlans[40].tagged)
            self.assertIn(portcafef00d_1, dp.vlans[41].tagged)
            self.assertIn(portcafef00d_2, dp.vlans[40].untagged)
            self.assertIn(portcafef00d_3, dp.vlans[40].untagged)
            self.assertIn(portcafef00d_3, dp.vlans[41].tagged)
            self.assertIn(portcafef00d_4, dp.vlans[41].untagged)
            self.assertIn(portcafef00d_5, dp.vlans[41].untagged)
            # check that the ports are not in vlans they should not be
{'fraction_non_alphanumeric': 0.10426376661488003, 'fraction_numerical': 0.03158984981874676, 'mean_word_length': 2.9414965986394557, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, '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': '4699285', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1900, 'n_words': 480}