Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

from foundations_spec import *
from foundations.job_parameters import flatten_parameter_dictionary

class TestFlattenParameterDictionary(Spec):

class TestFlattenParameterDictionary(Spec):
@let
def random_key(self):
return self.faker.word()
Expand All @@ -24,15 +23,20 @@ def random_literal_list_value(self):

@let
def random_literal_dict_value(self):
return {key: value for key, value in zip(self.random_literal_list(), self.random_literal_list())}
return {
key: value
for key, value in zip(
self.random_literal_list(), self.random_literal_list()
)
}

@let
def random_length(self):
return self.faker.random_int(1, 10)

@let
def random_int(self):
return self.faker.random_int(1,1000)
return self.faker.random_int(1, 1000)

@let
def random_float(self):
Expand All @@ -41,21 +45,31 @@ def random_float(self):
def test_flatten_empty_dictionary_returns_empty_dictionary(self):
parameter_input = {}
flattened_parameter_input = flatten_parameter_dictionary(parameter_input)

self.assertEqual({}, flattened_parameter_input)

def test_key_and_value_returns_key_and_value(self):
parameter_input = {self.random_key: self.random_string_literal}
flattened_parameter_input = flatten_parameter_dictionary(parameter_input)

self.assertEqual({self.random_key: self.random_string_literal}, flattened_parameter_input)
self.assertEqual(
{self.random_key: self.random_string_literal}, flattened_parameter_input
)

def test_key_with_value_of_list_of_literals_returns_key_concatenated_with_list_index(self):
def test_key_with_value_of_list_of_literals_returns_key_concatenated_with_list_index(
self,
):
parameter_input = {self.random_key: self.random_literal_list_value}
flattened_parameter_input = flatten_parameter_dictionary(parameter_input)

list_of_keys = map(lambda list_index: '{}_{}'.format(self.random_key, list_index), range(self.random_length))
expected_output = {key: value for key, value in zip(list_of_keys, self.random_literal_list_value)}
list_of_keys = map(
lambda list_index: f"{self.random_key}_{list_index}",
range(self.random_length),
)
expected_output = {
key: value
for key, value in zip(list_of_keys, self.random_literal_list_value)
}

self.assertEqual(expected_output, flattened_parameter_input)

Expand All @@ -69,8 +83,10 @@ def test_key_with_value_float_returns_key_and_value(self):
parameter_input = {self.random_key: self.random_float}
flattened_parameter_input = flatten_parameter_dictionary(parameter_input)

self.assertEqual({self.random_key: self.random_float}, flattened_parameter_input)

self.assertEqual(
{self.random_key: self.random_float}, flattened_parameter_input
)

def test_key_with_value_none_returns_key_and_value(self):
parameter_input = {self.random_key: None}
flattened_parameter_input = flatten_parameter_dictionary(parameter_input)
Expand All @@ -89,49 +105,53 @@ def test_key_with_value_empty_list_turns_value_dict_into_none(self):

self.assertEqual({self.random_key: None}, flattened_parameter_input)

def test_key_with_value_of_dict_of_literals_returns_key_concatenated_with_nested_dict_keys(self):
def test_key_with_value_of_dict_of_literals_returns_key_concatenated_with_nested_dict_keys(
self,
):
parameter_input = {self.random_key: self.random_literal_dict_value}
flattened_parameter_input = flatten_parameter_dictionary(parameter_input)

expected_output = {'{}_{}'.format(self.random_key, nested_key): nested_value for nested_key, nested_value in self.random_literal_dict_value.items()}
expected_output = {
f"{self.random_key}_{nested_key}": nested_value
for nested_key, nested_value in self.random_literal_dict_value.items()
}
self.assertEqual(expected_output, flattened_parameter_input)

def test_multiple_keys_with_at_most_singly_nested_values(self):
none_literal_key = self.faker.word()
int_literal_key = self.faker.word()
float_literal_key = self.faker.word()
string_literal_key = self.faker.word()
non_empty_dictionary_key = self.faker.word()
non_empty_list_key = self.faker.word()
empty_dictionary_key = self.faker.word()
empty_list_key = self.faker.word()

parameter_input = {
none_literal_key: None,
int_literal_key: self.random_int,
float_literal_key: self.random_float,
string_literal_key: self.random_string_literal,
empty_dictionary_key: {},
empty_list_key: [],
non_empty_list_key: self.random_literal_list_value,
non_empty_dictionary_key: self.random_literal_dict_value
"none_literal_key": None,
"int_literal_key": self.random_int,
"float_literal_key": self.random_float,
"string_literal_key": self.random_string_literal,
"empty_dictionary_key": {},
"empty_list_key": [],
"non_empty_list_key": self.random_literal_list_value,
"non_empty_dictionary_key": self.random_literal_dict_value,
}

expected_output = {
none_literal_key: None,
int_literal_key: self.random_int,
float_literal_key: self.random_float,
string_literal_key: self.random_string_literal,
empty_dictionary_key: None,
empty_list_key: None
"none_literal_key": None,
"int_literal_key": self.random_int,
"float_literal_key": self.random_float,
"string_literal_key": self.random_string_literal,
"empty_dictionary_key": None,
"empty_list_key": None,
}

list_of_keys = map(lambda list_index: '{}_{}'.format(non_empty_list_key, list_index), range(self.random_length))
list_output = {key: value for key, value in zip(list_of_keys, self.random_literal_list_value)}
list_of_keys = map(
lambda list_index: f"non_empty_list_key_{list_index}",
range(self.random_length),
)
list_output = {
key: value
for key, value in zip(list_of_keys, self.random_literal_list_value)
}

expected_output.update(list_output)

expected_dict_output = {'{}_{}'.format(non_empty_dictionary_key, nested_key): nested_value for nested_key, nested_value in self.random_literal_dict_value.items()}
expected_dict_output = {
f"non_empty_dictionary_key_{nested_key}": nested_value
for nested_key, nested_value in self.random_literal_dict_value.items()
}

expected_output.update(expected_dict_output)

Expand All @@ -140,29 +160,22 @@ def test_multiple_keys_with_at_most_singly_nested_values(self):
def test_value_is_list_of_lists_flattens_correctly(self):
parameter_input = {self.random_key: [[0, 1], [2, 3]]}
expected_output = {
self.random_key + '_0_0': 0,
self.random_key + '_0_1': 1,
self.random_key + '_1_0': 2,
self.random_key + '_1_1': 3
self.random_key + "_0_0": 0,
self.random_key + "_0_1": 1,
self.random_key + "_1_0": 2,
self.random_key + "_1_1": 3,
}

self.assertEqual(expected_output, flatten_parameter_dictionary(parameter_input))

def test_value_is_dict_of_dicts_flattens_correctly(self):
parameter_input = {
self.random_key: {
'key_zero': {
'hello': 'there'
},
'key_one': {
'bye': 'bye'
}
}
self.random_key: {"key_zero": {"hello": "there"}, "key_one": {"bye": "bye"}}
}

expected_output = {
self.random_key + '_key_zero_hello': 'there',
self.random_key + '_key_one_bye': 'bye'
self.random_key + "_key_zero_hello": "there",
self.random_key + "_key_one_bye": "bye",
}

self.assertEqual(expected_output, flatten_parameter_dictionary(parameter_input))
self.assertEqual(expected_output, flatten_parameter_dictionary(parameter_input))
5 changes: 3 additions & 2 deletions atlas_installer/build.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/bin/bash

export build_version=$(python get_version.py)
release_version=$(echo $build_version | sed "s/.dev[0-9]*//")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the change is great ... I like the option to use regex to get rid of the dev from the version ... I think @amackillop you should also consider that there are several things that use this version strategy ... I'm wondering what else this will impact....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular change only seems to impact which URL is used in the installer to download the release from github. I left the exporting of the original build version in case that is pulled from somewhere later but I don't think that it is.

root_dir="$(pwd)"
base_dir="${root_dir}/atlas_installer"
working_dir="${base_dir}/dist"

rm -rf $working_dir \
&& mkdir -p $working_dir \
&& echo "Building atlas installer script..." \
&& echo "Copying the current atlas version (${build_version}) into the installer file" \
&& sed "s/There is no version information available./${build_version}/g" \
&& echo "Copying the current atlas version (${release_version}) into the installer file" \
&& sed "s/There is no version information available./${release_version}/g" \
$base_dir/atlas_installer.py > $working_dir/atlas_installer_before_notice.py \
&& echo "Compressing the notice into a tar file" \
&& tar -zcvf $working_dir/licenses.tgz NOTICE.md > /dev/null 2>&1 \
Expand Down