<commit_before>
use strict;
use warnings;

use lib 't/lib/';
use Hive::Config;
use File::Spec::Functions qw{catdir};
use File::Temp qw{tempdir};
use Hive::Test qw{spurt};
use Test::More;
use Data::Dumper;

BEGIN {
    use_ok( 'Bio::EnsEMBL::Hive::Utils::Config' );
    
}
#########################


my @config_files = Bio::EnsEMBL::Hive::Utils::Config->default_config_files();
diag "@config_files"; 

cmp_ok(@config_files, '>', 0, 'at least one got returned');
cmp_ok(@config_files, '<', 3, '1 or 2');

my $config = bless {_config_hash => {}}, 'Bio::EnsEMBL::Hive::Utils::Config';

my $dir = tempdir CLEANUP => 1;
my $json = catdir $dir, 'test.json';
spurt <<EOF, $json;
{
    "Meadow" : {
        "OPENLAVA"  : {
	    "TotalRunningWorkersMax" : 1000,
	    "omics" : {
		"SubmissionOptions" : "-q special-branch"
	    }
	}
    },
}
EOF

my $simple = $config->load_from_json($json);
isa_ok($simple, 'HASH');
ok(exists($simple->{'Meadow'}), 'exists');

my $simpler = $config->load_from_json($json . '.notexist');
is($simpler, undef, 'undef, but no death');

$config->merge($simple);
my $merged = $config->config_hash;
ok($merged, 'merged hash');


$config = Bio::EnsEMBL::Hive::Utils::Config->new();
ok($config, 'new instance');


my $content = $config->config_hash;

isa_ok($content, 'HASH');
ok(exists($content->{'Meadow'}), 'Ok you are in a forest. Forest? With Heather...');

isa_ok($content->{'Meadow'}, 'HASH');

ok(exists($content->{'Valley'}), 'alpine valley?');

isa_ok($content->{'Valley'}, 'HASH');

ok(exists($content->{'Graph'}), 'lets plot that');

isa_ok($content->{'Graph'}, 'HASH');

ok(exists($content->{'VERSION'}), 'party on');

$config->merge($simple);
my $merged_hash = $config->config_hash;
isa_ok($merged_hash, 'HASH');
ok(exists($merged_hash->{'Meadow'}{'OPENLAVA'}),                               'first level merge');
ok(exists($merged_hash->{'Meadow'}{'OPENLAVA'}{'omics'}),                      'second level merge');
ok(exists($merged_hash->{'Meadow'}{'OPENLAVA'}{'omics'}{'SubmissionOptions'}), 'third level merge');
is($merged_hash->{'Meadow'}{'OPENLAVA'}{'TotalRunningWorkersMax'}, 1000,       'data check');

my $ol_submission_opts = $config->get(qw{Meadow OPENLAVA omics SubmissionOptions});
is($ol_submission_opts, '-q special-branch', 'get() functions');

$config->set(qw{Meadow OPENLAVA TotalRunningWorkersMax}, 20);
my $ol_total = $config->get(qw{Meadow OPENLAVA TotalRunningWorkersMax});
is($ol_total, 20, 'roundtrip set() and get() function');

done_testing();
<commit_msg>remove needless diagnostic<commit_after>
use strict;
use warnings;

use lib 't/lib/';
use Hive::Config;
use File::Spec::Functions qw{catdir};
use File::Temp qw{tempdir};
use Hive::Test qw{spurt};
use Test::More;
use Data::Dumper;

BEGIN {
    use_ok( 'Bio::EnsEMBL::Hive::Utils::Config' );
    
}
#########################


my @config_files = Bio::EnsEMBL::Hive::Utils::Config->default_config_files();
# diag "@config_files"; 

cmp_ok(@config_files, '>', 0, 'at least one got returned');
cmp_ok(@config_files, '<', 3, '1 or 2');

my $config = bless {_config_hash => {}}, 'Bio::EnsEMBL::Hive::Utils::Config';

my $dir = tempdir CLEANUP => 1;
my $json = catdir $dir, 'test.json';
spurt <<EOF, $json;
{
    "Meadow" : {
        "OPENLAVA"  : {
	    "TotalRunningWorkersMax" : 1000,
	    "omics" : {
		"SubmissionOptions" : "-q special-branch"
	    }
	}
    },
}
EOF

my $simple = $config->load_from_json($json);
isa_ok($simple, 'HASH');
ok(exists($simple->{'Meadow'}), 'exists');

my $simpler = $config->load_from_json($json . '.notexist');
is($simpler, undef, 'undef, but no death');

$config->merge($simple);
my $merged = $config->config_hash;
ok($merged, 'merged hash');


$config = Bio::EnsEMBL::Hive::Utils::Config->new();
ok($config, 'new instance');


my $content = $config->config_hash;

isa_ok($content, 'HASH');
ok(exists($content->{'Meadow'}), 'Ok you are in a forest. Forest? With Heather...');

isa_ok($content->{'Meadow'}, 'HASH');

ok(exists($content->{'Valley'}), 'alpine valley?');

isa_ok($content->{'Valley'}, 'HASH');

ok(exists($content->{'Graph'}), 'lets plot that');

isa_ok($content->{'Graph'}, 'HASH');

ok(exists($content->{'VERSION'}), 'party on');

$config->merge($simple);
my $merged_hash = $config->config_hash;
isa_ok($merged_hash, 'HASH');
ok(exists($merged_hash->{'Meadow'}{'OPENLAVA'}),                               'first level merge');
ok(exists($merged_hash->{'Meadow'}{'OPENLAVA'}{'omics'}),                      'second level merge');
ok(exists($merged_hash->{'Meadow'}{'OPENLAVA'}{'omics'}{'SubmissionOptions'}), 'third level merge');
is($merged_hash->{'Meadow'}{'OPENLAVA'}{'TotalRunningWorkersMax'}, 1000,       'data check');

my $ol_submission_opts = $config->get(qw{Meadow OPENLAVA omics SubmissionOptions});
is($ol_submission_opts, '-q special-branch', 'get() functions');

$config->set(qw{Meadow OPENLAVA TotalRunningWorkersMax}, 20);
my $ol_total = $config->get(qw{Meadow OPENLAVA TotalRunningWorkersMax});
is($ol_total, 20, 'roundtrip set() and get() function');

done_testing();

{'fraction_non_alphanumeric': 0.22555048601467964, 'fraction_numerical': 0.006744693513191827, 'mean_word_length': 5.616797900262467, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 57, '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': '5244930', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1830, 'n_words': 362}