<commit_before># -*- coding: utf-8 -*-

from __future__ import division, unicode_literals, print_function, absolute_import

from pyvisa import constants
from pyvisa.compat import unittest
from pyvisa.testsuite import BaseTestCase

pyvisapy = __import__('pyvisa-py')

parse = pyvisapy.common.parse_resource_name


class TestParsers(BaseTestCase):

    def _parse_test(self, rn, **kwargs):
        result = dict(resource_name=rn, **kwargs)
        self.assertEqual(parse(rn), result)

    @unittest.expectedFailure
    def test_asrl_ethernet(self):
        self._parse_test('ASRL::1.2.3.4::2::INSTR',
                         interface_type=constants.InterfaceType.asrl,
                         resource_class='INSTR',
                         port='2',
                         address='1.2.3.4')

    def test_asrl(self):
        self._parse_test('ASRL1::INSTR',
                         interface_type=constants.InterfaceType.asrl,
                         resource_class='INSTR',
                         board='1',
                         canonical_resource_name='ASRL1::INSTR')

        self._parse_test('ASRL1',
                         interface_type=constants.InterfaceType.asrl,
                         resource_class='INSTR',
                         board='1',
                         canonical_resource_name='ASRL1::INSTR')

    def test_gpib_instr(self):
        self._parse_test('GPIB::1::0::INSTR',
                         interface_type=constants.InterfaceType.gpib,
                         resource_class='INSTR',
                         board='0',
                         primary_address='1',
                         secondary_address='0',
                         canonical_resource_name='GPIB0::1::0::INSTR')

        self._parse_test('GPIB::1::INSTR',
                         interface_type=constants.InterfaceType.gpib,
                         resource_class='INSTR',
                         board='0',
                         primary_address='1',
                         secondary_address=65535,
                         canonical_resource_name='GPIB0::1::65535::INSTR')

        self._parse_test('GPIB1::1::INSTR',
                         interface_type=constants.InterfaceType.gpib,
                         resource_class='INSTR',
                         board='1',
                         primary_address='1',
                         secondary_address=65535,
                         canonical_resource_name='GPIBfdf8:f53e:61e4::18::65535::INSTR')

        self._parse_test('GPIBfdf8:f53e:61e4::18',
                         interface_type=constants.InterfaceType.gpib,
                         resource_class='INSTR',
                         board='1',
                         primary_address='1',
                         secondary_address=65535,
                         canonical_resource_name='GPIBfdf8:f53e:61e4::18::65535::INSTR')

    def test_gpib_intf(self):
        self._parse_test('GPIB::INTFC',
                         interface_type=constants.InterfaceType.gpib,
                         resource_class='INTFC',
                         board='0',
                         canonical_resource_name='GPIB0::INTFC')

        self._parse_test('GPIB3::INTFC',
                         interface_type=constants.InterfaceType.gpib,
                         resource_class='INTFC',
                         board='3',
                         canonical_resource_name='GPIB3::INTFC')

    def test_tcpip_intr(self):
        self._parse_test('TCPIP::dev.company.com::INSTR',
                         interface_type=constants.InterfaceType.tcpip,
                         resource_class='INSTR',
                         host_address='dev.company.com',
                         board='0',<commit_msg>Add TCPIP test<commit_after># -*- coding: utf-8 -*-

from __future__ import division, unicode_literals, print_function, absolute_import

from pyvisa import constants
from pyvisa.compat import unittest
from pyvisa.testsuite import BaseTestCase

pyvisapy = __import__('pyvisa-py')

parse = pyvisapy.common.parse_resource_name


class TestParsers(BaseTestCase):

    def _parse_test(self, rn, **kwargs):
        result = dict(resource_name=rn, **kwargs)
        self.assertEqual(parse(rn), result)

    @unittest.expectedFailure
    def test_asrl_ethernet(self):
        self._parse_test('ASRL::1.2.3.4::2::INSTR',
                         interface_type=constants.InterfaceType.asrl,
                         resource_class='INSTR',
                         port='2',
                         address='1.2.3.4')

    def test_asrl(self):
        self._parse_test('ASRL1::INSTR',
                         interface_type=constants.InterfaceType.asrl,
                         resource_class='INSTR',
                         board='1',
                         canonical_resource_name='ASRL1::INSTR')

        self._parse_test('ASRL1',
                         interface_type=constants.InterfaceType.asrl,
                         resource_class='INSTR',
                         board='1',
                         canonical_resource_name='ASRL1::INSTR')

    def test_gpib_instr(self):
        self._parse_test('GPIB::1::0::INSTR',
                         interface_type=constants.InterfaceType.gpib,
                         resource_class='INSTR',
                         board='0',
                         primary_address='1',
                         secondary_address='0',
                         canonical_resource_name='GPIB0::1::0::INSTR')

        self._parse_test('GPIB::1::INSTR',
                         interface_type=constants.InterfaceType.gpib,
                         resource_class='INSTR',
                         board='0',
                         primary_address='1',
                         secondary_address=65535,
                         canonical_resource_name='GPIB0::1::65535::INSTR')

        self._parse_test('GPIB1::1::INSTR',
                         interface_type=constants.InterfaceType.gpib,
                         resource_class='INSTR',
                         board='1',
                         primary_address='1',
                         secondary_address=65535,
                         canonical_resource_name='GPIB1::1::65535::INSTR')

        self._parse_test('GPIB1::1',
                         interface_type=constants.InterfaceType.gpib,
                         resource_class='INSTR',
                         board='1',
                         primary_address='1',
                         secondary_address=65535,
                         canonical_resource_name='GPIB1::1::65535::INSTR')

    def test_gpib_intf(self):
        self._parse_test('GPIB::INTFC',
                         interface_type=constants.InterfaceType.gpib,
                         resource_class='INTFC',
                         board='0',
                         canonical_resource_name='GPIB0::INTFC')

        self._parse_test('GPIB3::INTFC',
                         interface_type=constants.InterfaceType.gpib,
                         resource_class='INTFC',
                         board='3',
                         canonical_resource_name='GPIB3::INTFC')

    def test_tcpip_intr(self):

        self._parse_test('TCPIP::192.168.134.102',
                         interface_type=constants.InterfaceType.tcpip,
                         resource_class='INSTR',
                         host_address='192.168.134.102',
                         board='0',
                         lan_device_name='inst0',
                         canonical_resource_name='TCPIP0::192.168.134.102::inst0::INSTR')

        self._parse_test('TCPIP::dev.company.com::INSTR',
                         interface_type=constants.InterfaceType.tcpip,
                         resource_class='INSTR',
                         host_address='dev.company.com',
                         board='0',
{'fraction_non_alphanumeric': 0.10219905936189144, 'fraction_numerical': 0.027202237193339265, 'mean_word_length': 1.468005018820577, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 7, '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': '4606749', 'n_tokens_mistral': 2162, 'n_tokens_neox': 1961, 'n_words': 220}