# Path: capirca/lib/nacaddr.py
# def IP(ip, comment='', token='', strict=True):
# def _is_subnet_of(a, b):  # pylint: disable=invalid-name
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def AddComment(self, comment=''):
#   def supernet(self, prefixlen_diff=1):
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def supernet(self, prefixlen_diff=1):
#   def AddComment(self, comment=''):
# def _InNetList(adders, ip):
# def IsSuperNet(supernets, subnets):
# def CollapseAddrListPreserveTokens(addresses):
# def _SafeToMerge(address, merge_target, check_addresses):
# def _CollapseAddrListInternal(addresses, complements_by_network):
# def CollapseAddrList(addresses, complement_addresses=None):
# def SortAddrList(addresses):
# def RemoveAddressFromList(superset, exclude):
# def AddressListExclude(superset, excludes, collapse_addrs=True):
# class IPv4(ipaddress.IPv4Network):
# class IPv6(ipaddress.IPv6Network):
# class PrefixlenDiffInvalidError(ipaddress.NetmaskValueError):
# 
# Path: capirca/lib/naming.py
# class Error(Exception):
# class NamespaceCollisionError(Error):
# class BadNetmaskTypeError(Error):
# class NoDefinitionsError(Error):
# class ParseError(Error):
# class UndefinedAddressError(Error):
# class UndefinedServiceError(Error):
# class UndefinedPortError(Error):
# class UnexpectedDefinitionTypeError(Error):
# class NamingSyntaxError(Error):
# class _ItemUnit:
# class Naming:
#   def __init__(self, symbol):
#   def __init__(self, naming_dir=None, naming_file=None, naming_type=None):
#   def _CheckUnseen(self, def_type):
#   def GetIpParents(self, query):
#   def GetServiceParents(self, query):
#   def GetNetParents(self, query):
#   def _GetParents(self, query, query_group):
#   def GetNetChildren(self, query):
#   def _GetChildren(self, query, query_group):
#   def _IsIpFormat(self, item):
#   def GetServiceNames(self):
#   def GetService(self, query):
#   def GetPortParents(self, query, proto):
#   def GetServiceByProto(self, query, proto):
#   def GetNetAddr(self, token):
#   def GetNet(self, query):
#   def _Parse(self, defdirectory, def_type):
#   def _ParseFile(self, file_handle, def_type):
#   def ParseServiceList(self, data):
#   def ParseNetworkList(self, data):
#   def _ParseLine(self, line, definition_type):
# 
# Path: tools/cgrep.py
# def is_valid_ip(arg):
# def cli_options():
# def main(argv):
# def check_encapsulated(obj_type, first_obj, second_obj, db):
# def print_diff(ip, common, diff1, diff2):
# def group_diff(options, db):
# def get_ip_parents(ip, db):
# def get_nets_and_highest_prefix(ip, net_group, db):
# def get_nets(objects, db):
# def compare_tokens(options, db):
# def compare_ip_token(options, db):
# def get_ports(svc_group, db):
# def get_services(options, db):


import argparse
from absl.testing import absltest
from capirca.lib import nacaddr
from capirca.lib import naming
from tools import cgrep

  # 22/tcp does not belong to TELNET
  def test_get_port_parents_fail(self):
    expected_results = (r'22', r'tcp', ['TELNET'])
    options = Namespace()
    options.port = ('22', 'tcp')
    results = cgrep.get_services(options, self.db)
    self.assertNotEqual(results, expected_results)

  # 33434/tcp should only be in HIGH_PORTS (not also TRACEROUTE)
  def test_get_port_parents_range_tcp(self):
    expected_results = (r'33434', r'tcp', ['HIGH_PORTS'])
    options = Namespace()
    options.port = ('33434', 'tcp')
    results = cgrep.get_services(options, self.db)
    self.assertEqual(results, expected_results)

  # 33434/udp should be in HIGH_PORTS and TRACEROUTE
  def test_get_port_parents_range_udp(self):
    expected_results = (r'33434', r'udp', ['HIGH_PORTS', 'TRACEROUTE'])
    options = Namespace()
    options.port = ('33434', 'udp')
    results = cgrep.get_services(options, self.db)
    self.assertEqual(results, expected_results)

  #
  # test IP validity
  #
  def test_invalid_ip(self):
    self.assertRaises(argparse.ArgumentTypeError,

# Path: capirca/lib/nacaddr.py
# def IP(ip, comment='', token='', strict=True):
# def _is_subnet_of(a, b):  # pylint: disable=invalid-name
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def AddComment(self, comment=''):
#   def supernet(self, prefixlen_diff=1):
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def supernet(self, prefixlen_diff=1):
#   def AddComment(self, comment=''):
# def _InNetList(adders, ip):
# def IsSuperNet(supernets, subnets):
# def CollapseAddrListPreserveTokens(addresses):
# def _SafeToMerge(address, merge_target, check_addresses):
# def _CollapseAddrListInternal(addresses, complements_by_network):
# def CollapseAddrList(addresses, complement_addresses=None):
# def SortAddrList(addresses):
# def RemoveAddressFromList(superset, exclude):
# def AddressListExclude(superset, excludes, collapse_addrs=True):
# class IPv4(ipaddress.IPv4Network):
# class IPv6(ipaddress.IPv6Network):
# class PrefixlenDiffInvalidError(ipaddress.NetmaskValueError):
# 
# Path: capirca/lib/naming.py
# class Error(Exception):
# class NamespaceCollisionError(Error):
# class BadNetmaskTypeError(Error):
# class NoDefinitionsError(Error):
# class ParseError(Error):
# class UndefinedAddressError(Error):
# class UndefinedServiceError(Error):
# class UndefinedPortError(Error):
# class UnexpectedDefinitionTypeError(Error):
# class NamingSyntaxError(Error):
# class _ItemUnit:
# class Naming:
#   def __init__(self, symbol):
#   def __init__(self, naming_dir=None, naming_file=None, naming_type=None):
#   def _CheckUnseen(self, def_type):
#   def GetIpParents(self, query):
#   def GetServiceParents(self, query):
#   def GetNetParents(self, query):
#   def _GetParents(self, query, query_group):
#   def GetNetChildren(self, query):
#   def _GetChildren(self, query, query_group):
#   def _IsIpFormat(self, item):
#   def GetServiceNames(self):
#   def GetService(self, query):
#   def GetPortParents(self, query, proto):
#   def GetServiceByProto(self, query, proto):
#   def GetNetAddr(self, token):
#   def GetNet(self, query):
#   def _Parse(self, defdirectory, def_type):
#   def _ParseFile(self, file_handle, def_type):
#   def ParseServiceList(self, data):
#   def ParseNetworkList(self, data):
#   def _ParseLine(self, line, definition_type):
# 
# Path: tools/cgrep.py
# def is_valid_ip(arg):
# def cli_options():
# def main(argv):
# def check_encapsulated(obj_type, first_obj, second_obj, db):
# def print_diff(ip, common, diff1, diff2):
# def group_diff(options, db):
# def get_ip_parents(ip, db):
# def get_nets_and_highest_prefix(ip, net_group, db):
# def get_nets(objects, db):
# def compare_tokens(options, db):
# def compare_ip_token(options, db):
# def get_ports(svc_group, db):
# def get_services(options, db):


# Path: tests/lib/cgrep_test.py
import argparse
from absl.testing import absltest
from capirca.lib import nacaddr
from capirca.lib import naming
from tools import cgrep


  # 22/tcp does not belong to TELNET
  def test_get_port_parents_fail(self):
    expected_results = (r'22', r'tcp', ['TELNET'])
    options = Namespace()
    options.port = ('22', 'tcp')
    results = cgrep.get_services(options, self.db)
    self.assertNotEqual(results, expected_results)

  # 33434/tcp should only be in HIGH_PORTS (not also TRACEROUTE)
  def test_get_port_parents_range_tcp(self):
    expected_results = (r'33434', r'tcp', ['HIGH_PORTS'])
    options = Namespace()
    options.port = ('33434', 'tcp')
    results = cgrep.get_services(options, self.db)
    self.assertEqual(results, expected_results)

  # 33434/udp should be in HIGH_PORTS and TRACEROUTE
  def test_get_port_parents_range_udp(self):
    expected_results = (r'33434', r'udp', ['HIGH_PORTS', 'TRACEROUTE'])
    options = Namespace()
    options.port = ('33434', 'udp')
    results = cgrep.get_services(options, self.db)
    self.assertEqual(results, expected_results)

  #
  # test IP validity
  #
  def test_invalid_ip(self):
    self.assertRaises(argparse.ArgumentTypeError,

                      cgrep.is_valid_ip, '10.0.0.256')