<commit_before>require 'spec_helper_acceptance'

describe 'python class' do
  context 'default parameters' do
    # Using puppet_apply as a helper
    it 'works with no errors' do
      pp = <<-EOS
      class { 'python' :
        version    => 'system',
        pip        => 'present',
        virtualenv => 'present',
      }
      -> python::virtualenv { 'venv' :
        ensure     => 'present',
        systempkgs => false,
        venv_dir   => '/opt/venv',
        owner      => 'root',
        group      => 'root',
      }
      -> python::pip { 'rpyc' :
        ensure     => '3.2.3',
        virtualenv => '/opt/venv',
      }
      EOS

      # Run it twice and test for idempotency
      apply_manifest(pp, catch_failures: true)
      apply_manifest(pp, catch_changes: true)
    end

    it 'maintains pip version' do
      pp = <<-EOS
      class { 'python' :
        version    => 'system',
        pip        => 'present',
        virtualenv => 'present',
      }
      -> python::virtualenv { 'venv' :
        ensure     => 'present',
        systempkgs => false,
        venv_dir   => '/opt/venv2',
        owner      => 'root',
        group      => 'root',
      }
      -> python::pip { 'pip' :
        ensure     => '18.0',
        virtualenv => '/opt/venv2',
      }
      EOS

      # Run it twice and test for idempotency
      apply_manifest(pp, catch_failures: true)
      apply_manifest(pp, catch_changes: true)
    end

    it 'works with ensure=>latest' do
      pp = <<-EOS
      class { 'python' :
        version    => 'system',
        pip        => 'present',
        virtualenv => 'present',
      }
      -> python::virtualenv { 'venv' :
        ensure     => 'present',
        systempkgs => false,
        venv_dir   => '/opt/venv3',
        owner      => 'root',
        group      => 'root',
      }
      -> python::pip { 'rpyc' :
        ensure     => 'latest',
        virtualenv => '/opt/venv3',
      }
      EOS

      # Run it twice and test for idempotency
      apply_manifest(pp, catch_failures: true)
      # Of course this test will fail if between the applies a new version of the package will be released,
      # but probability of this happening is minimal, so it should be acceptable.
      apply_manifest(pp, catch_changes: true)
    end

    it 'works with ensure=>latest for package with underscore in its name' do
      pp = <<-EOS
      class { 'python' :
        version    => 'system',
        pip        => 'present',
        virtualenv => 'present',
      }
      -> python::virtualenv { 'venv' :
        ensure     => 'present',
        systempkgs => false,
        venv_dir   => '/opt/venv4',
        owner      => 'root',
        group      => 'root',
      }
      -> python::pip { 'Randomized_Requests' :
        ensure     => 'latest',
        virtualenv => '/opt/venv4',
      }
      EOS

      # Run it twice and test for idempotency
      apply_manifest(pp, catch_failures: true)
      # Of course this test will fail if between the applies a new version of the package will be released,
      # but probability of this happening is minimal, so it should be acceptable.
      apply_manifest(pp, catch_changes: true)<commit_msg>Switch to int_date for acceptance test<commit_after>require 'spec_helper_acceptance'

describe 'python class' do
  context 'default parameters' do
    # Using puppet_apply as a helper
    it 'works with no errors' do
      pp = <<-EOS
      class { 'python' :
        version    => 'system',
        pip        => 'present',
        virtualenv => 'present',
      }
      -> python::virtualenv { 'venv' :
        ensure     => 'present',
        systempkgs => false,
        venv_dir   => '/opt/venv',
        owner      => 'root',
        group      => 'root',
      }
      -> python::pip { 'rpyc' :
        ensure     => '3.2.3',
        virtualenv => '/opt/venv',
      }
      EOS

      # Run it twice and test for idempotency
      apply_manifest(pp, catch_failures: true)
      apply_manifest(pp, catch_changes: true)
    end

    it 'maintains pip version' do
      pp = <<-EOS
      class { 'python' :
        version    => 'system',
        pip        => 'present',
        virtualenv => 'present',
      }
      -> python::virtualenv { 'venv' :
        ensure     => 'present',
        systempkgs => false,
        venv_dir   => '/opt/venv2',
        owner      => 'root',
        group      => 'root',
      }
      -> python::pip { 'pip' :
        ensure     => '18.0',
        virtualenv => '/opt/venv2',
      }
      EOS

      # Run it twice and test for idempotency
      apply_manifest(pp, catch_failures: true)
      apply_manifest(pp, catch_changes: true)
    end

    it 'works with ensure=>latest' do
      pp = <<-EOS
      class { 'python' :
        version    => 'system',
        pip        => 'present',
        virtualenv => 'present',
      }
      -> python::virtualenv { 'venv' :
        ensure     => 'present',
        systempkgs => false,
        venv_dir   => '/opt/venv3',
        owner      => 'root',
        group      => 'root',
      }
      -> python::pip { 'rpyc' :
        ensure     => 'latest',
        virtualenv => '/opt/venv3',
      }
      EOS

      # Run it twice and test for idempotency
      apply_manifest(pp, catch_failures: true)
      # Of course this test will fail if between the applies a new version of the package will be released,
      # but probability of this happening is minimal, so it should be acceptable.
      apply_manifest(pp, catch_changes: true)
    end

    it 'works with ensure=>latest for package with underscore in its name' do
      pp = <<-EOS
      class { 'python' :
        version    => 'system',
        pip        => 'present',
        virtualenv => 'present',
      }
      -> python::virtualenv { 'venv' :
        ensure     => 'present',
        systempkgs => false,
        venv_dir   => '/opt/venv4',
        owner      => 'root',
        group      => 'root',
      }
      -> python::pip { 'int_date' :
        ensure     => 'latest',
        virtualenv => '/opt/venv4',
      }
      EOS

      # Run it twice and test for idempotency
      apply_manifest(pp, catch_failures: true)
      # Of course this test will fail if between the applies a new version of the package will be released,
      # but probability of this happening is minimal, so it should be acceptable.
      apply_manifest(pp, catch_changes: true)
{'fraction_non_alphanumeric': 0.12048567870485678, 'fraction_numerical': 0.0037359900373599006, 'mean_word_length': 1.7270797962648556, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '650832', 'n_tokens_mistral': 1929, 'n_tokens_neox': 1880, 'n_words': 556}