Ejemplo n.º 1
0
    def test_description(self):
        # ARRANGE #

        s1 = 'string1'
        s2 = 'string2'

        cases = [
            NameAndValue('empty',
                         [],
                         ),
            NameAndValue('singleton fragment',
                         [s1],
                         ),
            NameAndValue('multiple fragments',
                         [s1, s2],
                         ),
        ]
        for case in cases:
            with self.subTest(case.name):
                expected = ''.join(case.value)
                fragments = [
                    strings.ConstantFragmentDdv(s)
                    for s in case.value
                ]
                string = strings.StringDdv(fragments)

                # ACT #

                actual = string.describer().render()

                # ASSERT #

                self.assertEqual(expected, actual)
Ejemplo n.º 2
0
 def test_fail(self):
     actual = csv.ConstantFragmentDdv('actual value')
     expected = AMultiDirDependentValue(
         resolving_dependencies=set(),
         get_value_when_no_dir_dependencies=do_return('expected value'),
         get_value_of_any_dependency=do_return('expected value'))
     assertion = sut.equals_string_fragment_ddv(expected)
     assert_that_assertion_fails(assertion, actual)
Ejemplo n.º 3
0
    def test_pass(self):
        actual = csv.ConstantFragmentDdv('fragment value')
        expected = AMultiDirDependentValue(
            resolving_dependencies=set(),
            get_value_when_no_dir_dependencies=do_return('fragment value'),
            get_value_of_any_dependency=do_return('fragment value'))

        assertion = sut.equals_string_fragment_ddv(expected)
        assertion.apply_without_message(self, actual)
Ejemplo n.º 4
0
 def test_resolve_should_give_string_constant(self):
     # ARRANGE #
     string_constant = 'string constant'
     fragment = impl.ConstantStringFragmentSdv(string_constant)
     # ACT #
     actual = fragment.resolve(empty_symbol_table())
     # ASSERT #
     assertion = equals_string_fragment_ddv(
         csv.ConstantFragmentDdv(string_constant))
     assertion.apply_without_message(self, actual)
Ejemplo n.º 5
0
    def test_description(self):
        # ARRANGE #
        fragment_string = 'fragment string'
        fragment = strings.ConstantFragmentDdv(fragment_string)

        # ACT #

        actual = fragment.describer().render()

        # ASSERT #

        self.assertEqual(fragment_string, actual)
Ejemplo n.º 6
0
 def test_resolve_of_string_symbol_SHOULD_give_string_constant(self):
     # ARRANGE #
     symbol = StringConstantSymbolContext('the_symbol_name',
                                          'the symbol value')
     symbol_reference = symbol.reference__w_str_rendering
     fragment = impl.SymbolStringFragmentSdv(symbol_reference)
     symbol_table = symbol.symbol_table
     # ACT #
     actual = fragment.resolve(symbol_table)
     # ASSERT #
     self.assertIsInstance(actual, csv.StringDdvFragmentDdv)
     assertion = equals_string_fragment_ddv(
         csv.ConstantFragmentDdv(symbol.str_value))
     assertion.apply_without_message(self, actual)
Ejemplo n.º 7
0
 def test_pass(self):
     cases = [
         (
             'no fragments',
             sut.StringDdv(tuple([])),
         ),
         (
             'single fragment',
             sut.StringDdv(tuple([csv.ConstantFragmentDdv('fragment value')])),
         ),
     ]
     for name, value in cases:
         with self.subTest(name=name):
             assertion = sut.equals_string_ddv(value)
             assertion.apply_without_message(self, value)
Ejemplo n.º 8
0
    def test_description(self):
        # ARRANGE #
        transformed_string = 'the string'
        expected = transformed_string.upper()

        fragment = strings.TransformedStringFragmentDdv(strings.ConstantFragmentDdv(transformed_string),
                                                        str.upper)

        # ACT #

        actual = fragment.describer().render()

        # ASSERT #

        self.assertEqual(expected, actual)
Ejemplo n.º 9
0
 def test_dir_dependence(self):
     cases = [
         NEA(
             'single string constant fragment',
             expected=AMultiDirDependentValue(
                 resolving_dependencies=set(),
                 get_value_when_no_dir_dependencies=do_return('fragment'),
                 get_value_of_any_dependency=do_return('fragment')),
             actual=strings.ConstantFragmentDdv('fragment'),
         ),
     ]
     for case in cases:
         assertion = matches_multi_dir_dependent_value(case.expected)
         with self.subTest(name=case.name,
                           expected=str(case.expected)):
             assertion.apply_without_message(self, case.actual)
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
    def test_resolve(self):
        string_constant_1 = 'string constant 1'
        string_constant_2 = 'string constant 2'
        string_symbol = StringConstantSymbolContext('string_symbol_name',
                                                    'string symbol value')
        path_symbol = ConstantSuffixPathDdvSymbolContext(
            'path_symbol_name', RelOptionType.REL_ACT, 'file-name')
        list_symbol = ListConstantSymbolContext(
            'list_symbol_name', ['list element 1', 'list element 2'])

        cases = [
            (
                'no fragments',
                sut.StringSdv(()),
                empty_symbol_table(),
                csv.StringDdv(()),
            ),
            (
                'single string constant fragment',
                sut.StringSdv(
                    (impl.ConstantStringFragmentSdv(string_constant_1), )),
                empty_symbol_table(),
                csv.StringDdv((csv.ConstantFragmentDdv(string_constant_1), )),
            ),
            (
                'multiple single string constant fragments',
                sut.StringSdv(
                    (impl.ConstantStringFragmentSdv(string_constant_1),
                     impl.ConstantStringFragmentSdv(string_constant_2))),
                empty_symbol_table(),
                csv.StringDdv((csv.ConstantFragmentDdv(string_constant_1),
                               csv.ConstantFragmentDdv(string_constant_2))),
            ),
            (
                'single symbol fragment/symbol is a string',
                sut.StringSdv((impl.SymbolStringFragmentSdv(
                    string_symbol.reference__w_str_rendering), )),
                string_symbol.symbol_table,
                csv.StringDdv(
                    (csv.ConstantFragmentDdv(string_symbol.str_value), )),
            ),
            (
                'single symbol fragment/symbol is a path',
                sut.StringSdv((impl.SymbolStringFragmentSdv(
                    path_symbol.reference__w_str_rendering), )),
                path_symbol.symbol_table,
                csv.StringDdv((csv.PathFragmentDdv(path_symbol.ddv), )),
            ),
            (
                'single symbol fragment/symbol is a list',
                sut.StringSdv((impl.SymbolStringFragmentSdv(
                    list_symbol.reference__w_str_rendering), )),
                list_symbol.symbol_table,
                csv.StringDdv((csv.ListFragmentDdv(list_symbol.ddv), )),
            ),
            (
                'multiple fragments of different types',
                sut.StringSdv((
                    impl.SymbolStringFragmentSdv(
                        string_symbol.reference__w_str_rendering),
                    impl.ConstantStringFragmentSdv(string_constant_1),
                    impl.SymbolStringFragmentSdv(
                        path_symbol.reference__w_str_rendering),
                    impl.SymbolStringFragmentSdv(
                        list_symbol.reference__w_str_rendering),
                )),
                SymbolContext.symbol_table_of_contexts([
                    string_symbol,
                    path_symbol,
                    list_symbol,
                ]),
                csv.StringDdv((
                    csv.ConstantFragmentDdv(string_symbol.str_value),
                    csv.ConstantFragmentDdv(string_constant_1),
                    csv.PathFragmentDdv(path_symbol.ddv),
                    csv.ListFragmentDdv(list_symbol.ddv),
                )),
            ),
        ]
        for test_name, string_value, symbol_table, expected in cases:
            with self.subTest(test_name=test_name):
                actual = string_value.resolve(symbol_table)
                assertion = equals_string_ddv(expected)
                assertion.apply_without_message(self, actual)
Ejemplo n.º 12
0
 def resolve(self, symbols: SymbolTable) -> sv.StringFragmentDdv:
     return csv.ConstantFragmentDdv(self._constant)
Ejemplo n.º 13
0
    def test_fail__different_fragment_value(self):
        actual = sut.StringDdv(tuple([csv.ConstantFragmentDdv('actual fragment value')]))
        expected = sut.StringDdv(tuple([csv.ConstantFragmentDdv('expected fragment value')]))

        assertion = sut.equals_string_ddv(expected)
        assert_that_assertion_fails(assertion, actual)
Ejemplo n.º 14
0
 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)