def test_get_special_survey_cols(): (special, t, tc) = _get_special_survey_cols(_s([ 'type', 'media::image', 'media::image::English', 'label::Français', 'label', 'label::English', 'media::audio::chinese', 'label: Arabic', 'label :: German', 'label:English', 'hint:English', ])) assert sorted(special.keys()) == sorted([ 'label', 'media::image', 'media::image::English', 'label::Français', 'label::English', 'media::audio::chinese', 'label: Arabic', 'label :: German', 'label:English', 'hint:English', ]) values = [special[key] for key in sorted(special.keys())] assert sorted(map(lambda x: x.get('translation'), values) ) == sorted(['English', 'English', 'English', 'English', 'chinese', 'Arabic', 'German', 'Français', UNTRANSLATED, UNTRANSLATED])
def test_not_special_cols(): not_special = [ 'bind::orx:for', 'bind:jr:constraintMsg', 'bind:relevant', 'body::accuracyThreshold', 'body::accuracyTreshold', 'body::acuracyThreshold', 'body:accuracyThreshold', ] (not_special, _t, tc) = _get_special_survey_cols(_s(not_special)) assert not_special.keys() == []
def test_ordered_dict_preserves_order(): (special, t, tc) = _get_special_survey_cols({ 'survey': [ OrderedDict([ ('label::A', 'A'), ('label::B', 'B'), ('label::C', 'C'), ]) ] }) assert t == ['A', 'B', 'C'] (special, t, tc) = _get_special_survey_cols({ 'survey': [ OrderedDict([ ('label::C', 'C'), ('label::B', 'B'), ('label::A', 'A'), ]) ] }) assert t == ['C', 'B', 'A']
def test_get_special_survey_cols(): (special, t, tc) = _get_special_survey_cols( _s([ 'type', 'media::image', 'media::image::English', 'label::Français', 'label', 'label::English', 'media::audio::chinese', 'label: Arabic', 'label :: German', 'label:English', 'hint:English', ])) assert sorted(special.keys()) == sorted([ 'label', 'media::image', 'media::image::English', 'label::Français', 'label::English', 'media::audio::chinese', 'label: Arabic', 'label :: German', 'label:English', 'hint:English', ]) values = [special[key] for key in sorted(special.keys())] translations = sorted([x.get('translation') for x in values], key=orderable_with_none) expected = sorted( [ 'English', 'English', 'English', 'English', 'chinese', 'Arabic', 'German', 'Français', UNTRANSLATED, UNTRANSLATED, ], key=orderable_with_none, ) assert translations == expected