コード例 #1
0
 def test_list_constant(self):
     # ARRANGE #
     constant = ['a', 'b' 'c']
     # ACT #
     actual = list_sdvs.from_str_constants(constant)
     # ASSERT #
     self.assertEqual([], actual.references,
                      'references')
     actual_value = actual.resolve(empty_symbol_table())
     expected_value = AMultiDirDependentValue(resolving_dependencies=set(),
                                              get_value_when_no_dir_dependencies=do_return(constant),
                                              get_value_of_any_dependency=do_return(constant))
     matches_multi_dir_dependent_value(expected_value).apply_with_message(self, actual_value, 'resolve value')
コード例 #2
0
ファイル: string_ddv.py プロジェクト: emilkarlen/exactly
 def test(self):
     cases = [
         (
             'single string constant fragment',
             strings.TransformedStringFragmentDdv(strings.ConstantFragmentDdv('fragment'),
                                                  str.upper),
             AMultiDirDependentValue(
                 resolving_dependencies=set(),
                 get_value_when_no_dir_dependencies=do_return('FRAGMENT'),
                 get_value_of_any_dependency=do_return('FRAGMENT')),
         ),
     ]
     for test_case_name, actual, expected in cases:
         assertion = matches_multi_dir_dependent_value(expected)
         with self.subTest(name=test_case_name,
                           expected=str(expected)):
             assertion.apply_without_message(self, actual)
コード例 #3
0
 def test_pass(self):
     cases = [
         AMultiDirDependentValue(
             resolving_dependencies=set(),
             get_value_when_no_dir_dependencies=do_return(
                 'value when no dep'),
             get_value_of_any_dependency=do_return('value')),
         AMultiDirDependentValue(
             resolving_dependencies={DirectoryStructurePartition.HDS},
             get_value_of_any_dependency=do_return(
                 'value_of_any_dependency')),
         AMultiDirDependentValue(
             resolving_dependencies={DirectoryStructurePartition.NON_HDS},
             get_value_of_any_dependency=do_return(
                 'value_of_any_dependency'))
     ]
     for value in cases:
         with self.subTest(value=str(value)):
             assertion = sut.matches_multi_dir_dependent_value(value)
             assertion.apply_without_message(self, value)
コード例 #4
0
ファイル: string_ddv.py プロジェクト: emilkarlen/exactly
 def test(self):
     path_rel_home = path_ddvs.of_rel_option(path_ddvs.RelOptionType.REL_HDS_CASE,
                                             PathPartDdvAsNothing())
     path_rel_sds = path_ddvs.of_rel_option(path_ddvs.RelOptionType.REL_ACT,
                                            PathPartDdvAsNothing())
     path_abs = path_ddvs.absolute_file_name(str(pathlib.Path().resolve()))
     cases = [
         (
             'dependency on ' + str(DirectoryStructurePartition.HDS),
             strings.PathFragmentDdv(path_rel_home),
             AMultiDirDependentValue(
                 resolving_dependencies={DirectoryStructurePartition.HDS},
                 get_value_of_any_dependency=lambda h_s: str(
                     path_rel_home.value_pre_sds(h_s.hds))),
         ),
         (
             'dependency on ' + str(DirectoryStructurePartition.NON_HDS),
             strings.PathFragmentDdv(path_rel_sds),
             AMultiDirDependentValue(
                 resolving_dependencies={DirectoryStructurePartition.NON_HDS},
                 get_value_of_any_dependency=lambda h_s: str(
                     path_rel_sds.value_post_sds(h_s.sds))),
         ),
         (
             'no dependency',
             strings.PathFragmentDdv(path_abs),
             AMultiDirDependentValue(
                 resolving_dependencies=set(),
                 get_value_when_no_dir_dependencies=do_return(str(path_abs.value_when_no_dir_dependencies())),
                 get_value_of_any_dependency=lambda h_s: str(
                     path_abs.value_when_no_dir_dependencies())),
         ),
     ]
     for test_case_name, expected, actual in cases:
         assertion = matches_multi_dir_dependent_value(expected)
         with self.subTest(name=test_case_name,
                           expected=str(expected)):
             assertion.apply_without_message(self, actual)
コード例 #5
0
ファイル: string_ddv.py プロジェクト: emilkarlen/exactly
 def test(self):
     string_of_path_rel_home = string_ddv_of_single_path(
         path_ddvs.of_rel_option(path_ddvs.RelOptionType.REL_HDS_CASE,
                                 PathPartDdvAsNothing()))
     string_1 = 'string value 1'
     string_2 = 'string value 2'
     cases = [
         (
             'single string constant element',
             strings.ListFragmentDdv(strings.ListDdv([string_ddv_of_single_string(string_1)])),
             AMultiDirDependentValue(
                 resolving_dependencies=set(),
                 get_value_when_no_dir_dependencies=do_return(string_1),
                 get_value_of_any_dependency=do_return(string_1)),
         ),
         (
             'multiple string constant element',
             strings.ListFragmentDdv(strings.ListDdv([string_ddv_of_single_string(string_1),
                                                      string_ddv_of_single_string(string_2)])),
             AMultiDirDependentValue(
                 resolving_dependencies=set(),
                 get_value_when_no_dir_dependencies=do_return(list_formatting.format_elements([string_1, string_2])),
                 get_value_of_any_dependency=do_return(list_formatting.format_elements([string_1, string_2]))),
         ),
         (
             'dependency on ' + str(DirectoryStructurePartition.HDS),
             strings.ListFragmentDdv(strings.ListDdv([string_of_path_rel_home])),
             AMultiDirDependentValue(
                 resolving_dependencies={DirectoryStructurePartition.HDS},
                 get_value_of_any_dependency=lambda h_s: str(
                     string_of_path_rel_home.value_of_any_dependency(h_s))),
         ),
     ]
     for test_case_name, expected, actual in cases:
         assertion = matches_multi_dir_dependent_value(expected)
         with self.subTest(name=test_case_name):
             assertion.apply_without_message(self, actual)
コード例 #6
0
 def _assert_not_equal(expected: sut.MultiDependenciesDdv,
                       actual: sut.MultiDependenciesDdv):
     assertion = sut.matches_multi_dir_dependent_value(expected)
     assert_that_assertion_fails(assertion, actual)
コード例 #7
0
 def test_dependence_and_resolving(self):
     string_fragment_1 = 'string fragment 1'
     string_fragment_2 = 'string fragment 2'
     path_rel_home = path_ddvs.of_rel_option(
         path_ddvs.RelOptionType.REL_HDS_CASE, PathPartDdvAsNothing())
     path_rel_sds = path_ddvs.of_rel_option(path_ddvs.RelOptionType.REL_ACT,
                                            PathPartDdvAsNothing())
     single_element_with_dep_on_home = sv.string_ddv_of_single_path(
         path_rel_home)
     single_element_with_dep_on_sds = sv.string_ddv_of_single_path(
         path_rel_sds)
     cases = [
         (
             'no elements',
             sut.ListDdv([]),
             AMultiDirDependentValue(
                 resolving_dependencies=set(),
                 get_value_when_no_dir_dependencies=do_return([]),
                 get_value_of_any_dependency=do_return([])),
         ),
         (
             'single string constant element',
             sut.ListDdv(
                 [sv.string_ddv_of_single_string(string_fragment_1)]),
             AMultiDirDependentValue(
                 resolving_dependencies=set(),
                 get_value_when_no_dir_dependencies=do_return(
                     [string_fragment_1]),
                 get_value_of_any_dependency=do_return([string_fragment_1
                                                        ])),
         ),
         (
             'multiple string constant element',
             sut.ListDdv([
                 sv.string_ddv_of_single_string(string_fragment_1),
                 sv.string_ddv_of_single_string(string_fragment_2)
             ]),
             AMultiDirDependentValue(
                 resolving_dependencies=set(),
                 get_value_when_no_dir_dependencies=do_return(
                     [string_fragment_1, string_fragment_2]),
                 get_value_of_any_dependency=do_return(
                     [string_fragment_1, string_fragment_2])),
         ),
         (
             'single dir dependent value/pre sds',
             sut.ListDdv([single_element_with_dep_on_home]),
             AMultiDirDependentValue(
                 resolving_dependencies={DirectoryStructurePartition.HDS},
                 get_value_of_any_dependency=lambda h_s: [
                     single_element_with_dep_on_home.
                     value_of_any_dependency(h_s)
                 ]),
         ),
         (
             'single dir dependent value/post sds',
             sut.ListDdv([single_element_with_dep_on_sds]),
             AMultiDirDependentValue(
                 resolving_dependencies={
                     DirectoryStructurePartition.NON_HDS
                 },
                 get_value_of_any_dependency=lambda h_s: [
                     single_element_with_dep_on_sds.value_of_any_dependency(
                         h_s)
                 ]),
         ),
         (
             'multiple dir dependent value/pre sds + post sds',
             sut.ListDdv([
                 single_element_with_dep_on_home,
                 single_element_with_dep_on_sds
             ]),
             AMultiDirDependentValue(
                 resolving_dependencies={
                     DirectoryStructurePartition.HDS,
                     DirectoryStructurePartition.NON_HDS
                 },
                 get_value_of_any_dependency=lambda h_s: [
                     single_element_with_dep_on_home.
                     value_of_any_dependency(h_s),
                     single_element_with_dep_on_sds.value_of_any_dependency(
                         h_s)
                 ]),
         ),
     ]
     for test_case_name, expected, actual in cases:
         assertion = matches_multi_dir_dependent_value(expected)
         with self.subTest(name=test_case_name):
             assertion.apply_without_message(self, actual)
コード例 #8
0
ファイル: string_ddv.py プロジェクト: emilkarlen/exactly
 def test(self):
     string_fragment_1 = 'string fragment 1'
     string_fragment_2 = 'string fragment 2'
     path_rel_home = path_ddvs.of_rel_option(path_ddvs.RelOptionType.REL_HDS_CASE,
                                             PathPartDdvAsNothing())
     path_rel_sds = path_ddvs.of_rel_option(path_ddvs.RelOptionType.REL_ACT,
                                            PathPartDdvAsNothing())
     cases = [
         (
             'no fragments',
             sut.StringDdv(tuple([])),
             AMultiDirDependentValue(
                 resolving_dependencies=set(),
                 get_value_when_no_dir_dependencies=do_return(''),
                 get_value_of_any_dependency=do_return('')),
         ),
         (
             'single string constant fragment',
             sut.StringDdv(tuple([strings.ConstantFragmentDdv(string_fragment_1)])),
             AMultiDirDependentValue(
                 resolving_dependencies=set(),
                 get_value_when_no_dir_dependencies=do_return(string_fragment_1),
                 get_value_of_any_dependency=do_return(string_fragment_1)),
         ),
         (
             'multiple string constant fragment',
             sut.StringDdv(tuple([strings.ConstantFragmentDdv(string_fragment_1),
                                  strings.ConstantFragmentDdv(string_fragment_2)])),
             AMultiDirDependentValue(
                 resolving_dependencies=set(),
                 get_value_when_no_dir_dependencies=do_return(string_fragment_1 + string_fragment_2),
                 get_value_of_any_dependency=do_return(string_fragment_1 + string_fragment_2)),
         ),
         (
             'single dir dependent value/pre sds',
             sut.StringDdv(tuple([strings.PathFragmentDdv(path_rel_home)])),
             AMultiDirDependentValue(
                 resolving_dependencies={DirectoryStructurePartition.HDS},
                 get_value_of_any_dependency=lambda h_s: str(
                     path_rel_home.value_pre_sds(h_s.hds))),
         ),
         (
             'single dir dependent value/post sds',
             sut.StringDdv(tuple([strings.PathFragmentDdv(path_rel_sds)])),
             AMultiDirDependentValue(
                 resolving_dependencies={DirectoryStructurePartition.NON_HDS},
                 get_value_of_any_dependency=lambda h_s: str(
                     path_rel_sds.value_post_sds(h_s.sds))),
         ),
         (
             'multiple dir dependent value/pre sds + post sds',
             sut.StringDdv(tuple([strings.PathFragmentDdv(path_rel_home),
                                  strings.PathFragmentDdv(path_rel_sds)])),
             AMultiDirDependentValue(
                 resolving_dependencies={DirectoryStructurePartition.HDS,
                                         DirectoryStructurePartition.NON_HDS},
                 get_value_of_any_dependency=lambda h_s: (
                         str(path_rel_home.value_pre_sds(h_s.hds)) +
                         str(path_rel_sds.value_post_sds(h_s.sds)))
             ),
         ),
     ]
     for test_case_name, expected, actual in cases:
         assertion = matches_multi_dir_dependent_value(expected)
         with self.subTest(name=test_case_name,
                           expected=str(expected)):
             assertion.apply_without_message(self, actual)