<commit_before># Copyright (c) 2015-2016 Cisco and/or its affiliates.
#
# 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.

require_relative 'ciscotest'
require_relative '../lib/cisco_node_utils/platform'

# TestPlatform - Minitest for Platform class
class TestPlatform < CiscoTestCase
  def test_image_version
    case platform
    when :ios_xr
      refute_empty(Platform.image_version)

    when :nexus
      # Supported Images:
      # N3/9k: 7.0(3)I2(*), 7.0(3)I3(1)
      # N7k:   7.3(1)D1(1)
      # N5/6k: 7.3(0)N1(1)

      in_pat = '(^  NXOS: version |^  system:    version)'
      s = @device.cmd("show version | i '#{in_pat}'")

      out_pat = %r{/(\d\.\d\(\d\)[IDN])\d\(\d\)/}
      show = s.match(out_pat).to_s
      plat = Platform.image_version.match(out_pat).to_s
      assert_equal(show, plat)
    end
  end

  def test_system_image
    if platform == :ios_xr
      assert_nil(Platform.system_image)
    elsif platform == :nexus
      s = @device.cmd('show version | inc image | exc kickstart').scan(/ (\S+)$/).flatten.first
      assert_equal(s, Platform.system_image)
    end
  end

  def test_packages
    # [['pack1', 'state1'], ['pack2', 'state2'], ...]
    # 'state' should always be a variant of Active or Inactive
    pkgs = @device.cmd('sh inst patch')
           .scan(/\n(\S+)\s+(\S*[aA]ctive.*)\n/)
    # convert to hash with key pkg_name and value pkg_state
    pkg_hsh = {}
    pkgs.each { |p| pkg_hsh[p[0]] = p[1].downcase }
    assert_equal(pkg_hsh, Platform.packages)
  end<commit_msg>Fix test_platform regex<commit_after># Copyright (c) 2015-2016 Cisco and/or its affiliates.
#
# 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.

require_relative 'ciscotest'
require_relative '../lib/cisco_node_utils/platform'

# TestPlatform - Minitest for Platform class
class TestPlatform < CiscoTestCase
  def test_image_version
    case platform
    when :ios_xr
      refute_empty(Platform.image_version)

    when :nexus
      # Supported Images:
      # N3/9k: 7.0(3)I2(*), 7.0(3)I3(1)
      # N7k:   7.3(1)D1(1)
      # N5/6k: 7.3(0)N1(1)

      in_pat = '(^  NXOS: version |^  system:    version)'
      s = @device.cmd("show version | i '#{in_pat}'")

      out_pat = %r{/(\d\.\d\(\d\)[IDN])\d\(\d\)/}
      show = s.match(out_pat).to_s
      plat = Platform.image_version.match(out_pat).to_s
      assert_equal(show, plat)
    end
  end

  def test_system_image
    if platform == :ios_xr
      assert_nil(Platform.system_image)
    elsif platform == :nexus
      s = @device.cmd('show version | inc image | exc kickstart').scan(/ (\S+)$/).flatten.first
      assert_equal(s, Platform.system_image)
    end
  end

  def test_packages
    # [['pack1', 'state1'], ['pack2', 'state2'], ...]
    # 'state' should always be a variant of Active or Inactive
    pkgs = @device.cmd('sh inst patch')
           .scan(/\n(\S+)\s+(\S*[aA]ctive.*)/)
    # convert to hash with key pkg_name and value pkg_state
    pkg_hsh = {}
    pkgs.each { |p| pkg_hsh[p[0]] = p[1].downcase }
    assert_equal(pkg_hsh, Platform.packages)
  end
{'fraction_non_alphanumeric': 0.13057482656095143, 'fraction_numerical': 0.02081268582755203, 'mean_word_length': 3.119387755102041, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '775372', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1367, 'n_words': 391}