Esempio n. 1
0
 def test_equals(self):
     test_cases = [
         (
             'Plain string',
             string_sdvs.str_constant('string value'),
             empty_symbol_table(),
         ),
         (
             'String with reference',
             sdv_with_references([
                 SymbolReference(
                     'symbol_name',
                     ReferenceRestrictionsOnDirectAndIndirect(
                         ArbitraryValueWStrRenderingRestriction.of_any()))
             ]),
             empty_symbol_table(),
         ),
     ]
     for test_case_name, string_value, symbol_table in test_cases:
         assert isinstance(string_value, StringSdv), 'Type info for IDE'
         with self.subTest(msg='{}::with checked references::{}'.format(
                 sut.equals_string_sdv.__name__, test_case_name)):
             assertion = sut.equals_string_sdv(string_value)
             assertion.apply_with_message(self, string_value,
                                          test_case_name)
 def test_pass(self):
     a_symbol = NameAndValue('symbol name',
                             ASymbolTableValue('symbol value'))
     a_different_symbol = NameAndValue('a different symbol name',
                                       ASymbolTableValue('a different symbol value'))
     cases = [
         (
             'empty table',
             frozenset(),
             empty_symbol_table(),
         ),
         (
             'table with a single value',
             {a_symbol.name},
             SymbolTable({
                 a_symbol.name: a_symbol.value,
             }),
         ),
         (
             'table with a multiple values',
             {a_symbol.name,
              a_different_symbol.name},
             SymbolTable({
                 a_symbol.name: a_symbol.value,
                 a_different_symbol.name: a_different_symbol.value,
             }),
         ),
     ]
     for name, expected_keys, actual_symbol_table in cases:
         with self.subTest(name=name):
             # ARRANGE #
             assertion = sut.assert_symbol_table_keys_equals(expected_keys)
             # ACT #
             assertion.apply_without_message(self, actual_symbol_table)
Esempio n. 3
0
    def test_dissatisfied_restriction(self):
        # ARRANGE #
        cases = {
            ValueType.STRING: ValueType.LIST,
            ValueType.LIST: ValueType.PATH,
            ValueType.PATH: ValueType.INTEGER_MATCHER,
            ValueType.INTEGER_MATCHER: ValueType.FILE_MATCHER,
            ValueType.FILE_MATCHER: ValueType.FILES_MATCHER,
            ValueType.FILES_MATCHER: ValueType.STRING_SOURCE,
            ValueType.STRING_SOURCE: ValueType.STRING_MATCHER,
            ValueType.STRING_MATCHER: ValueType.STRING_TRANSFORMER,
            ValueType.STRING_TRANSFORMER: ValueType.PROGRAM,
            ValueType.PROGRAM: ValueType.FILES_CONDITION,
            ValueType.FILES_CONDITION: ValueType.FILES_SOURCE,
            ValueType.FILES_SOURCE: ValueType.STRING,
        }

        symbols = empty_symbol_table()
        for expected_value_type, unexpected_value_type in cases.items():
            container_of_unexpected = self.value_type_2_symbol_value_context_of_type[unexpected_value_type].container
            with self.subTest(expected_element_type=str(expected_value_type),
                              unexpected_element_type=str(unexpected_value_type)):
                restriction_to_check = sut.ValueTypeRestriction.of_single(expected_value_type)
                # ACT
                error_message = restriction_to_check.is_satisfied_by(symbols,
                                                                     'symbol name',
                                                                     container_of_unexpected)
                # ASSERT #
                self.assertIsNotNone(error_message)
Esempio n. 4
0
    def test_symbol_without_references(self):
        # ARRANGE #

        symbol_name = 'the_symbol_name'

        symbol_definition = _symbol_definition(
            symbol_name, string.ARBITRARY_SYMBOL_VALUE_CONTEXT)
        definitions_resolver = _ConstantDefinitionsResolver(
            [symbol_definition])

        report_generator = sut.IndividualReportGenerator(
            symbol_name, True, empty_symbol_table())

        # ACT #

        report = report_generator.generate(definitions_resolver)
        blocks = report.blocks()

        # ASSERT #

        self.assertTrue(report.is_success, 'is success')

        expected_blocks = asrt.is_empty_sequence

        expected_blocks.apply_with_message(self, blocks, 'blocks')

        _rendered_blocks_are_major_blocks(self, blocks)
Esempio n. 5
0
    def test_dissatisfied_restriction(self):
        # ARRANGE #
        cases = {
            ValueType.STRING: ValueType.LIST,
            ValueType.LIST: ValueType.PATH,
            ValueType.PATH: ValueType.FILE_MATCHER,
            ValueType.FILE_MATCHER: ValueType.STRING_TRANSFORMER,
            ValueType.FILES_MATCHER: ValueType.FILE_MATCHER,
            ValueType.STRING_MATCHER: ValueType.STRING_TRANSFORMER,
            ValueType.STRING_TRANSFORMER: ValueType.STRING,
            ValueType.PROGRAM: ValueType.STRING_TRANSFORMER,
        }

        symbols = empty_symbol_table()
        for expected_value_type, unexpected_value_type in cases.items():
            container_of_unexpected = container(self.value_type_2_resolver_of_type[unexpected_value_type])
            with self.subTest(expected_element_type=str(expected_value_type),
                              unexpected_element_type=str(unexpected_value_type)):
                restriction_to_check = sut.ValueTypeRestriction(expected_value_type)
                # ACT
                error_message = restriction_to_check.is_satisfied_by(symbols,
                                                                     'symbol name',
                                                                     container_of_unexpected)
                # ASSERT #
                self.assertIsNotNone(error_message)
 def test_pass(self):
     a_symbol = NameAndValue('symbol name',
                             ASymbolTableValue('symbol value'))
     a_different_symbol = NameAndValue(
         'a different symbol name',
         ASymbolTableValue('a different symbol value'))
     cases = [
         (
             'empty table',
             frozenset(),
             empty_symbol_table(),
         ),
         (
             'table with a single value',
             {a_symbol.name},
             SymbolTable({
                 a_symbol.name: a_symbol.value,
             }),
         ),
         (
             'table with a multiple values',
             {a_symbol.name, a_different_symbol.name},
             SymbolTable({
                 a_symbol.name: a_symbol.value,
                 a_different_symbol.name: a_different_symbol.value,
             }),
         ),
     ]
     for name, expected_keys, actual_symbol_table in cases:
         with self.subTest(name=name):
             # ARRANGE #
             assertion = sut.assert_symbol_table_keys_equals(expected_keys)
             # ACT #
             assertion.apply_without_message(self, actual_symbol_table)
 def test_differs__relativity(self):
     # ARRANGE #
     expected = FileRefTestImpl(RelOptionType.REL_ACT, file_refs.constant_path_part('file-name'))
     actual = FileRefTestImpl(RelOptionType.REL_HOME_CASE, file_refs.constant_path_part('file-name'))
     assertion = sut.matches_file_ref_resolver(expected, asrt.ignore, empty_symbol_table())
     # ACT & ASSERT #
     assert_that_assertion_fails(assertion, file_ref_resolvers.constant(actual))
Esempio n. 8
0
    def runTest(self):
        # ARRANGE #
        test_cases = [
            (PathPartDdvAsFixedPath('file.txt'), empty_symbol_table(),
             'file.txt'),
        ]
        tcds = fake_tcds()
        for path_suffix, symbol_table, expected_path_suffix in test_cases:
            with self.subTest():
                path = self.config.path_suffix_2_path(path_suffix)
                assert isinstance(path, PathDdv)
                # ACT #
                if self.config.resolving_dependency is None:
                    tested_path_msg = 'value_when_no_dir_dependencies'
                    actual_path = path.value_when_no_dir_dependencies()

                elif self.config.exists_pre_sds:
                    tested_path_msg = 'file_path_pre_sds'
                    actual_path = path.value_pre_sds(tcds.hds)
                else:
                    tested_path_msg = 'file_path_post_sds'
                    actual_path = path.value_post_sds(tcds.sds)
                actual_path_pre_or_post_sds = path.value_of_any_dependency(
                    tcds)
                # ASSERT #
                expected_relativity_root = self.config.tcds_2_relativity_root(
                    tcds)
                expected_path = expected_relativity_root / expected_path_suffix
                self.assertEqual(str(expected_path), str(actual_path),
                                 tested_path_msg)
                self.assertEqual(str(expected_path),
                                 str(actual_path_pre_or_post_sds),
                                 'file_path_pre_or_post_sds')
Esempio n. 9
0
 def test_differs__relativity(self):
     # ARRANGE #
     expected = PathDdvTestImpl(RelOptionType.REL_ACT, path_ddvs.constant_path_part('file-name'))
     actual = PathDdvTestImpl(RelOptionType.REL_HDS_CASE, path_ddvs.constant_path_part('file-name'))
     assertion = sut.matches_path_sdv(expected, asrt.ignore, empty_symbol_table())
     # ACT & ASSERT #
     assert_that_assertion_fails(assertion, path_sdvs.constant(actual))
Esempio n. 10
0
    def runTest(self):
        # ARRANGE #
        test_cases = [
            (PathPartAsFixedPath('file.txt'),
             empty_symbol_table(),
             'file.txt'
             ),
        ]
        home_and_sds = fake_home_and_sds()
        for path_suffix, symbol_table, expected_path_suffix in test_cases:
            with self.subTest():
                file_reference = self.config.path_suffix_2_file_ref(path_suffix)
                assert isinstance(file_reference, FileRef)
                # ACT #
                if self.config.resolving_dependency is None:
                    tested_path_msg = 'value_when_no_dir_dependencies'
                    actual_path = file_reference.value_when_no_dir_dependencies()

                elif self.config.exists_pre_sds:
                    tested_path_msg = 'file_path_pre_sds'
                    actual_path = file_reference.value_pre_sds(home_and_sds.hds)
                else:
                    tested_path_msg = 'file_path_post_sds'
                    actual_path = file_reference.value_post_sds(home_and_sds.sds)
                actual_path_pre_or_post_sds = file_reference.value_of_any_dependency(home_and_sds)
                # ASSERT #
                expected_relativity_root = self.config.home_and_sds_2_relativity_root(home_and_sds)
                expected_path = expected_relativity_root / expected_path_suffix
                self.assertEqual(str(expected_path),
                                 str(actual_path),
                                 tested_path_msg)
                self.assertEqual(str(expected_path),
                                 str(actual_path_pre_or_post_sds),
                                 'file_path_pre_or_post_sds')
Esempio n. 11
0
    def _new_processor(self,
                       recording_media: List[Recording],
                       test_case_processor_constructor: TestCaseProcessorConstructor) -> sut.Processor:
        test_case_definition = TestCaseDefinition(
            TestCaseParsingSetup(space_separator_instruction_name_extractor,
                                 self._phase_config().instructions_setup(REGISTER_INSTRUCTION_NAME, recording_media),
                                 self._phase_config().act_phase_parser()),
            PredefinedProperties({}, empty_symbol_table()))

        default_case_configuration = processors.Configuration(
            test_case_definition,
            TestCaseHandlingSetup(
                ActPhaseSetup(self._phase_config().actor(recording_media)),
                IDENTITY_PREPROCESSOR),
            os_services.DEFAULT_ATC_OS_PROCESS_EXECUTOR,
            False,
            sandbox_dir_resolving.mk_tmp_dir_with_prefix('test-suite-')
        )

        return sut.Processor(default_case_configuration,
                             suite_hierarchy_reading.Reader(
                                 suite_hierarchy_reading.Environment(
                                     SectionElementParserThatRaisesUnrecognizedSectionElementSourceError(),
                                     test_case_definition.parsing_setup,
                                     default_case_configuration.default_handling_setup)
                             ),
                             ProcessingReporterThatDoesNothing(),
                             enumeration.DepthFirstEnumerator(),
                             test_case_processor_constructor,
                             )
 def test_differs__exists_pre_sds(self):
     # ARRANGE #
     expected = FileRefTestImpl(_EXISTS_PRE_SDS_RELATIVITY, file_refs.constant_path_part('file-name'))
     actual = FileRefTestImpl(_NOT_EXISTS_PRE_SDS_RELATIVITY, file_refs.constant_path_part('file-name'))
     assertion = sut.matches_file_ref_resolver(expected, asrt.ignore, empty_symbol_table())
     # ACT & ASSERT #
     assert_that_assertion_fails(assertion, file_ref_resolvers.constant(actual))
Esempio n. 13
0
 def test_differs__exists_pre_sds(self):
     # ARRANGE #
     expected = PathDdvTestImpl(_EXISTS_PRE_SDS_RELATIVITY, path_ddvs.constant_path_part('file-name'))
     actual = PathDdvTestImpl(_NOT_EXISTS_PRE_SDS_RELATIVITY, path_ddvs.constant_path_part('file-name'))
     assertion = sut.matches_path_sdv(expected, asrt.ignore, empty_symbol_table())
     # ACT & ASSERT #
     assert_that_assertion_fails(assertion, path_sdvs.constant(actual))
 def __init__(self,
              symbol_references: list,
              source: ValueAssertion,
              symbol_table: SymbolTable = None):
     self.symbol_references = symbol_references
     self.source = source
     self.symbol_table = empty_symbol_table() if symbol_table is None else symbol_table
    def test_fail(self):
        a_symbol = NameAndValue('symbol name',
                                ASymbolTableValue('symbol value'))

        a_different_symbol = NameAndValue('a different symbol name',
                                          ASymbolTableValue('a different symbol value'))
        cases = [
            ('table is empty',
             empty_symbol_table(),
             a_symbol.name,
             asrt.anything_goes(),
             ),
            ('table is singleton but contains a different name',
             SymbolTable({a_symbol.name: a_symbol.value}),
             a_different_symbol.name,
             asrt.anything_goes(),
             ),
            ('table is singleton with given name but value assertion fails',
             SymbolTable({a_symbol.name: a_symbol.value}),
             a_symbol.name,
             assert_string_value_equals(a_different_symbol.value.value)
             ),
            ('table contains more than one element',
             SymbolTable({a_symbol.name: a_symbol.value,
                          a_different_symbol.name: a_different_symbol.value
                          }),
             a_symbol.name,
             asrt.anything_goes(),
             ),
        ]
        for name, table, symbol_name, value_assertion in cases:
            with self.subTest(name=name):
                assertion = sut.assert_symbol_table_is_singleton(symbol_name, value_assertion)
                assert_that_assertion_fails(assertion, table)
Esempio n. 16
0
 def test_strip_trailing_space(self):
     arguments = '  expected-argument  '
     instruction_embryo = self._parse_arguments(arguments)
     symbols = empty_symbol_table()
     file_ref = instruction_embryo.dir_path_resolver.resolve(symbols)
     equals_path_part_string('expected-argument').apply_with_message(self,
                                                                     file_ref.path_suffix(),
                                                                     'path_suffix')
Esempio n. 17
0
 def test_success_when_correct_number_of_arguments__escaped(self):
     arguments = '"expected argument"'
     instruction_embryo = self._parse_arguments(arguments)
     symbols = empty_symbol_table()
     file_ref = instruction_embryo.dir_path_resolver.resolve(symbols)
     equals_path_part_string('expected argument').apply_with_message(self,
                                                                     file_ref.path_suffix(),
                                                                     'path_suffix')
Esempio n. 18
0
 def test_resolve_without_symbol_references(self):
     string_constant_1 = 'string constant 1'
     string_constant_2 = 'string constant 2'
     string_symbol = NameAndValue('string_symbol_name', 'string symbol value')
     cases = [
         Case(
             'no elements',
             resolver_to_check=
             sut.ListResolver([]),
             symbols=
             empty_symbol_table(),
             expected_resolved_value=
             lv.ListValue([]),
         ),
         Case(
             'single constant element',
             resolver_to_check=
             sut.ListResolver([list_resolvers.str_element(string_constant_1)]),
             symbols=
             empty_symbol_table(),
             expected_resolved_value=
             lv.ListValue([string_value_of_single_string(string_constant_1)]),
         ),
         Case(
             'multiple constant elements',
             resolver_to_check=
             sut.ListResolver([list_resolvers.str_element(string_constant_1),
                               list_resolvers.str_element(string_constant_2)]),
             symbols=
             empty_symbol_table(),
             expected_resolved_value=
             lv.ListValue([string_value_of_single_string(string_constant_1),
                           string_value_of_single_string(string_constant_2)]),
         ),
         Case(
             'single string symbol reference element',
             resolver_to_check=
             sut.ListResolver([list_resolvers.symbol_element(su.symbol_reference(string_symbol.name))]),
             symbols=
             su.symbol_table_with_single_string_value(string_symbol.name,
                                                      string_symbol.value),
             expected_resolved_value=
             lv.ListValue([string_value_of_single_string(string_symbol.value)]),
         ),
     ]
     self._check('resolve without symbol references', cases)
Esempio n. 19
0
 def test_WHEN_no_usages_to_validate_THEN_validation_ok(
         self):
     # ARRANGE #
     symbol_table = empty_symbol_table()
     symbol_usages = []
     # ACT #
     actual = sut.validate_symbol_usages(symbol_usages, symbol_table)
     self.assertIsNone(actual, 'result should indicate ok')
Esempio n. 20
0
 def test_WHEN_no_usages_to_validate_THEN_validation_ok(
         self):
     # ARRANGE #
     symbol_table = empty_symbol_table()
     symbol_usages = []
     # ACT #
     actual = sut.validate_symbol_usages(symbol_usages, symbol_table)
     self.assertIsNone(actual, 'result should indicate ok')
Esempio n. 21
0
 def test_resolve_without_symbol_references(self):
     string_constant_1 = 'string constant 1'
     string_constant_2 = 'string constant 2'
     string_symbol = StringConstantSymbolContext('string_symbol_name', 'string symbol value')
     cases = [
         Case(
             'no elements',
             sdv_to_check=
             sut.ListSdv([]),
             symbols=
             empty_symbol_table(),
             expected_resolved_value=
             ListDdv([]),
         ),
         Case(
             'single constant element',
             sdv_to_check=
             sut.ListSdv([list_sdvs.str_element(string_constant_1)]),
             symbols=
             empty_symbol_table(),
             expected_resolved_value=
             ListDdv([string_ddv_of_single_string(string_constant_1)]),
         ),
         Case(
             'multiple constant elements',
             sdv_to_check=
             sut.ListSdv([list_sdvs.str_element(string_constant_1),
                          list_sdvs.str_element(string_constant_2)]),
             symbols=
             empty_symbol_table(),
             expected_resolved_value=
             ListDdv([string_ddv_of_single_string(string_constant_1),
                      string_ddv_of_single_string(string_constant_2)]),
         ),
         Case(
             'single string symbol reference element',
             sdv_to_check=
             sut.ListSdv([list_sdvs.symbol_element(string_symbol.reference__w_str_rendering)]),
             symbols=
             string_symbol.symbol_table,
             expected_resolved_value=
             ListDdv([string_ddv_of_single_string(string_symbol.str_value)]),
         ),
     ]
     self._check('resolve without symbol references', cases)
def matches_resolved_value(expected_resolved_primitive_lines: list,
                           symbol_references: list = None,
                           symbols: SymbolTable = None) -> ValueAssertion:
    symbols = empty_symbol_table() if symbols is None else symbols
    symbol_references = [] if symbol_references is None else symbol_references
    return string_assertions.matches_primitive_string(
        asrt.equals(contents_str_from_lines(expected_resolved_primitive_lines)),
        symbol_references,
        symbols)
Esempio n. 23
0
 def test_WHEN_referenced_symbol_not_in_symbol_table_THEN_validation_error(self):
     # ARRANGE #
     symbol_table = empty_symbol_table()
     symbol_usage = SymbolReference('undefined', reference_restrictions__unconditionally_satisfied())
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Esempio n. 24
0
 def test_add(self):
     # ARRANGE #
     symbol = NameAndValue('the symbol name',
                           ASymbolTableValue('the symbol value'))
     table = sut.empty_symbol_table()
     # ACT #
     table.add(sut.Entry(symbol.name, symbol.value))
     # ASSERT #
     _assert_table_contains_single_value(self, table, symbol)
Esempio n. 25
0
 def test_add(self):
     # ARRANGE #
     symbol = NameAndValue('the symbol name',
                           ASymbolTableValue('the symbol value'))
     table = sut.empty_symbol_table()
     # ACT #
     table.add(sut.Entry(symbol.name, symbol.value))
     # ASSERT #
     _assert_table_contains_single_value(self, table, symbol)
Esempio n. 26
0
 def test_WHEN_referenced_symbol_not_in_symbol_table_THEN_validation_error(self):
     # ARRANGE #
     symbol_table = empty_symbol_table()
     symbol_usage = su.SymbolReference('undefined', unconditionally_satisfied_reference_restrictions())
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Esempio n. 27
0
 def test_resolved_value(self):
     # ARRANGE #
     file_ref = FileRefTestImpl(RelOptionType.REL_TMP, file_refs.empty_path_part())
     resolver = sut.FileRefConstant(file_ref)
     # ACT #
     actual = resolver.resolve(empty_symbol_table())
     # ASSERT #
     assertion = equals_file_ref(file_ref)
     assertion.apply_without_message(self, actual)
Esempio n. 28
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)
Esempio n. 29
0
 def test_resolved_value(self):
     # ARRANGE #
     path = PathDdvTestImpl(RelOptionType.REL_TMP,
                            path_ddvs.empty_path_part())
     sdv = sut.PathConstantSdv(path)
     # ACT #
     actual = sdv.resolve(empty_symbol_table())
     # ASSERT #
     assertion = equals_path(path)
     assertion.apply_without_message(self, actual)
 def test(self):
     cases = [
         FailureOfDirectReference(ValueRestrictionFailure('error message')),
         FailureOfDirectReference(ValueRestrictionFailure('error message',
                                                          'how to fix')),
     ]
     for failure in cases:
         with self.subTest(msg=failure.error):
             actual = sut.error_message('checked_symbol', empty_symbol_table(), failure)
             self.assertIsInstance(actual, str)
def matches_resolved_value(
        expected_resolved_primitive_lines: Sequence[str],
        symbol_references: Optional[Sequence[SymbolReference]] = None,
        symbols: SymbolTable = None) -> Assertion[StringSdv]:
    symbols = empty_symbol_table() if symbols is None else symbols
    symbol_references = [] if symbol_references is None else symbol_references
    return exactly_lib_test.type_val_deps.types.string_.test_resources.sdv_assertions.matches_primitive_string(
        asrt.equals(
            contents_str_from_lines(expected_resolved_primitive_lines)),
        symbol_references, symbols)
 def test_with_and_without_references(self):
     test_cases = [
         ('Plain string',
          string_resolvers.str_constant('string value'),
          empty_symbol_table(),
          ),
         ('String with reference',
          resolver_with_references([SymbolReference('symbol_name',
                                                    ReferenceRestrictionsOnDirectAndIndirect(
                                                        AnyDataTypeRestriction()))]),
          empty_symbol_table(),
          ),
     ]
     for test_case_name, string_value, symbol_table in test_cases:
         assert isinstance(string_value, StringResolver), 'Type info for IDE'
         with self.subTest(msg='{}::with checked references::{}'.format(sut.equals_string_resolver.__name__,
                                                                        test_case_name)):
             assertion = sut.equals_string_resolver(string_value)
             assertion.apply_with_message(self, string_value, test_case_name)
 def test(self):
     cases = [
         FailureOfDirectReference(_new_em('error message')),
         FailureOfDirectReference(_new_em('error message',
                                          'how to fix')),
     ]
     for failure in cases:
         with self.subTest(msg=failure.error):
             actual = sut.ErrorMessage('checked_symbol', empty_symbol_table(), failure)
             asrt_text_doc.assert_is_valid_text_renderer(self, actual)
Esempio n. 34
0
 def test_resolve(self):
     # ARRANGE #
     path_part = sut.PathPartResolverAsFixedPath('the file name')
     # ACT #
     symbols = st.empty_symbol_table()
     actual = path_part.resolve(symbols)
     # ASSERT #
     self.assertIsInstance(actual, PathPart)
     self.assertEqual('the file name',
                      actual.value(),
                      'resolved file name')
def new_processor_with_no_symbols(registry: tr.Registry,
                                  test_case_processor_constructor: TestCaseProcessorConstructor) -> sut.Processor:
    return new_processor(
        {
            INSTR_DEFINE: tr.InstructionParserForDefine(),
            INSTR_REGISTER_EXISTENCE: tr.InstructionParserForRegistersExistenceOfSymbol(registry),
        }
        ,
        test_case_processor_constructor,
        PredefinedProperties({}, empty_symbol_table())
    )
 def test_differs__symbol_references(self):
     # ARRANGE #
     file_ref = FileRefTestImpl(RelOptionType.REL_ACT, file_refs.constant_path_part('file-name'))
     actual = _FileRefResolverWithConstantFileRefAndSymbolReferences(
         file_ref,
         [SymbolReference('symbol_name',
                          ReferenceRestrictionsOnDirectAndIndirect(AnyDataTypeRestriction()))])
     assertion = sut.matches_file_ref_resolver(file_ref,
                                               asrt.matches_sequence([]),
                                               empty_symbol_table())
     # ACT & ASSERT #
     assert_that_assertion_fails(assertion, actual)
Esempio n. 37
0
 def __init__(self,
              name: str,
              source: ParseSource,
              source_assertion: Assertion[ParseSource],
              references: Assertion[Sequence[SymbolReference]] = asrt.is_empty_sequence,
              symbols: SymbolTable = empty_symbol_table(),
              ):
     self.name = name
     self.source = source
     self.source_assertion = source_assertion
     self.references = references
     self.symbols = symbols
Esempio n. 38
0
 def test_WHEN_all_usages_are_valid_THEN_validation_ok(
         self):
     # ARRANGE #
     symbol_table = empty_symbol_table()
     valid_definition = StringSymbolContext.of_constant('symbol', 'value').definition
     valid__reference = SymbolReference('symbol', reference_restrictions__unconditionally_satisfied())
     symbol_usages = [
         valid_definition,
         valid__reference,
     ]
     # ACT #
     actual = sut.validate_symbol_usages(symbol_usages, symbol_table)
     self.assertIsNone(actual, 'result should indicate ok')
Esempio n. 39
0
 def test_differs__symbol_references(self):
     # ARRANGE #
     path = PathDdvTestImpl(RelOptionType.REL_ACT, path_ddvs.constant_path_part('file-name'))
     actual = PathSdvTestImplWithConstantPathAndSymbolReferences(
         path,
         [SymbolReference('symbol_name',
                          ReferenceRestrictionsOnDirectAndIndirect(
                              ArbitraryValueWStrRenderingRestriction.of_any()))])
     assertion = sut.matches_path_sdv(path,
                                      asrt.matches_sequence([]),
                                      empty_symbol_table())
     # ACT & ASSERT #
     assert_that_assertion_fails(assertion, actual)
Esempio n. 40
0
 def test_WHEN_all_usages_are_valid_THEN_validation_ok(
         self):
     # ARRANGE #
     symbol_table = empty_symbol_table()
     valid_definition = symbol_of('symbol')
     valid__reference = su.SymbolReference('symbol', unconditionally_satisfied_reference_restrictions())
     symbol_usages = [
         valid_definition,
         valid__reference,
     ]
     # ACT #
     actual = sut.validate_symbol_usages(symbol_usages, symbol_table)
     self.assertIsNone(actual, 'result should indicate ok')
Esempio n. 41
0
 def __init__(
     self,
     path_ddv: PathDdv,
     expected_symbol_references: List[SymbolReference],
     symbol_for_value_checks: Optional[SymbolTable] = None,
 ):
     self.symbol_for_value_checks = symbol_for_value_checks
     if symbol_for_value_checks is None:
         self.symbol_for_value_checks = empty_symbol_table()
     self.path_ddv = path_ddv
     self.expected_symbol_references = expected_symbol_references
     if self.expected_symbol_references is None:
         self.expected_symbol_references = []
Esempio n. 42
0
 def test_satisfied_restriction(self):
     # ARRANGE #
     symbols = empty_symbol_table()
     for expected_element_type in TypeCategory:
         container_of_resolver = container(self.element_type_2_resolver_of_type[expected_element_type])
         with self.subTest(element_type=str(expected_element_type)):
             restriction_to_check = sut.TypeCategoryRestriction(expected_element_type)
             # ACT
             error_message = restriction_to_check.is_satisfied_by(symbols,
                                                                  'symbol name',
                                                                  container_of_resolver)
             # ASSERT #
             self.assertIsNone(error_message)
Esempio n. 43
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')
Esempio n. 44
0
 def test_satisfied_restriction__multi(self):
     # ARRANGE #
     symbols = empty_symbol_table()
     for expected_value_type in ValueType:
         container_of_sdv = self.value_type_2_symbol_value_context_of_type[expected_value_type].container
         with self.subTest(element_type=str(expected_value_type)):
             restriction_to_check = sut.ValueTypeRestriction([expected_value_type, ValueType.STRING])
             # ACT
             error_message = restriction_to_check.is_satisfied_by(symbols,
                                                                  'symbol name',
                                                                  container_of_sdv)
             # ASSERT #
             self.assertIsNone(error_message)
Esempio n. 45
0
 def test_WHEN_updating_a_copy_THEN_the_copy_SHOULD_be_updated_but_not_the_original(self):
     # ARRANGE #
     symbol = NameAndValue('the symbol name',
                           ASymbolTableValue('the symbol value'))
     original_table = sut.empty_symbol_table()
     # ACT #
     copied_table = original_table.copy()
     copied_table.put(symbol.name, symbol.value)
     # ASSERT #
     _assert_table_contains_single_value(self,
                                         copied_table,
                                         symbol)
     _assert_table_is_empty(self,
                            original_table)
Esempio n. 46
0
 def test_WHEN_2nd_element_fails_to_validate_THEN_validation_error(self):
     # ARRANGE #
     symbol_table = empty_symbol_table()
     valid_definition = symbol_of('name-of-definition')
     invalid__reference = su.SymbolReference('undefined', unconditionally_satisfied_reference_restrictions())
     symbol_usages = [
         valid_definition,
         invalid__reference,
     ]
     # ACT #
     actual = sut.validate_symbol_usages(symbol_usages, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Esempio n. 47
0
 def test_WHEN_2nd_element_fails_to_validate_THEN_validation_error(self):
     # ARRANGE #
     symbol_table = empty_symbol_table()
     valid_definition = StringSymbolContext.of_constant('name-of-definition', 'value').definition
     invalid__reference = SymbolReference('undefined', reference_restrictions__unconditionally_satisfied())
     symbol_usages = [
         valid_definition,
         invalid__reference,
     ]
     # ACT #
     actual = sut.validate_symbol_usages(symbol_usages, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Esempio n. 48
0
 def test_WHEN_updating_a_copy_THEN_the_copy_SHOULD_be_updated_but_not_the_original(self):
     # ARRANGE #
     symbol = NameAndValue('the symbol name',
                           ASymbolTableValue('the symbol value'))
     original_table = sut.empty_symbol_table()
     # ACT #
     copied_table = original_table.copy()
     copied_table.put(symbol.name, symbol.value)
     # ASSERT #
     _assert_table_contains_single_value(self,
                                         copied_table,
                                         symbol)
     _assert_table_is_empty(self,
                            original_table)
Esempio n. 49
0
 def __init__(self,
              name: str,
              source: str,
              result: EquivalenceCheck,
              interval: PosNeg[Assertion[IntIntervalWInversion]],
              references: Assertion[Sequence[SymbolReference]] = asrt.is_empty_sequence,
              symbols: SymbolTable = empty_symbol_table(),
              ):
     self.name = name
     self.source = source
     self.result = result
     self.interval = interval
     self.references = references
     self.symbols = symbols
Esempio n. 50
0
    def _file_contents_cases(self) -> InvalidDestinationFileTestCasesData:
        file_contents_cases = [
            NameAndValue(
                'contents of here doc',
                here_document_contents_arguments(['contents'])
            ),
            NameAndValue(
                'contents of string',
                string_contents_arguments('contents')
            ),
        ]

        return InvalidDestinationFileTestCasesData(
            file_contents_cases,
            empty_symbol_table())
Esempio n. 51
0
 def test_pass(self):
     # ARRANGE #
     test_cases = [
         string_resolvers.str_constant('string'),
         string_resolvers.str_constant(''),
     ]
     restriction = vr.StringRestriction()
     symbols = empty_symbol_table()
     for value in test_cases:
         with self.subTest(msg='value=' + str(value)):
             container = data_symbol_utils.container(value)
             # ACT #
             actual = restriction.is_satisfied_by(symbols, 'symbol_name', container)
             # ASSERT #
             self.assertIsNone(actual)
Esempio n. 52
0
 def test_pass(self):
     # ARRANGE #
     test_cases = [
         StringSymbolValueContext.of_constant('string'),
         StringSymbolValueContext.of_constant(''),
     ]
     restriction = sut.is_string()
     symbols = empty_symbol_table()
     for value in test_cases:
         with self.subTest(msg='value=' + str(value)):
             # ACT #
             actual = restriction.is_satisfied_by(symbols, 'symbol_name',
                                                  value.container)
             # ASSERT #
             self.assertIsNone(actual)
 def test_difference_in_relativity_root(self):
     symbols = empty_symbol_table()
     for relativity in _RELATIVITY_VARIANTS:
         for path_suffix in _PATH_SUFFIX_VARIANTS:
             test_case_descr = 'relativity:{}, path-suffix: {}'.format(relativity, type(path_suffix))
             file_ref = FileRefTestImpl(relativity, path_suffix)
             file_ref_resolver = file_ref_resolvers.constant(file_ref)
             with self.subTest(msg=sut.equals_file_ref_resolver.__name__ + ' :: ' + test_case_descr):
                 assertion = sut.equals_file_ref_resolver(file_ref_resolver)
                 assertion.apply_without_message(self, file_ref_resolver)
             with self.subTest(msg=sut.matches_file_ref_resolver.__name__ + ' :: ' + test_case_descr):
                 assertion = sut.matches_file_ref_resolver(file_ref,
                                                           equals_symbol_references(file_ref_resolver.references),
                                                           symbols)
                 assertion.apply_without_message(self, file_ref_resolver)
Esempio n. 54
0
def resolving_helper(
    symbols: Optional[SymbolTable] = None,
    tcds: TestCaseDs = fake_tcds(),
    file_space: DirFileSpace = DirFileSpaceThatMustNoBeUsed(),
    os_services_: OsServices = os_services_access.new_for_current_os(),
    process_execution_settings:
    ProcessExecutionSettings = ProcessExecutionSettings.null(),
    mem_buff_size: int = 2**10,
) -> LogicTypeResolvingHelper:
    return LogicTypeResolvingHelper(
        (symbols if symbols is not None else empty_symbol_table()),
        tcds,
        ApplicationEnvironment(os_services_, process_execution_settings,
                               file_space, mem_buff_size),
    )
Esempio n. 55
0
 def test_fail__not_a_string(self):
     # ARRANGE #
     test_cases = [
         file_ref_constant_resolver(),
         FileMatcherResolverConstantTestImpl(FileMatcherTestImpl()),
     ]
     restriction = vr.StringRestriction()
     symbols = empty_symbol_table()
     for value in test_cases:
         with self.subTest(msg='value=' + str(value)):
             container = data_symbol_utils.container(value)
             # ACT #
             actual = restriction.is_satisfied_by(symbols, 'symbol_name', container)
             # ASSERT #
             self.assertIsNotNone(actual,
                                  'Result should denote failing validation')
Esempio n. 56
0
 def runTest(self):
     # ARRANGE #
     conf = self.configuration
     arguments_str = _exe_file_syntax_str(conf, 'file.exe',
                                          'remaining args')
     source = ParseSource(arguments_str)
     # ACT #
     exe_file = parse_executable_file_path.parser().parse(source)
     # ASSERT #
     source_assertion = has_remaining_part_of_first_line('remaining args')
     source_assertion.apply_with_message(self, source, 'source after parse')
     symbols = empty_symbol_table()
     self._check_existence_pre_sds(exe_file, symbols)
     with tcds_with_act_as_curr_dir(symbols=symbols) as environment:
         self._check_file_path('file.exe', exe_file, environment)
         self._assert_does_not_pass_validation(exe_file, environment)
Esempio n. 57
0
 def test_fail_WHEN_type_category_is_not_data(self):
     # ARRANGE #
     test_cases = [
         FileMatcherResolverConstantTestImpl(FileMatcherTestImpl()),
         StringTransformerResolverConstantTestImpl(FakeStringTransformer(), []),
     ]
     restriction = vr.AnyDataTypeRestriction()
     symbols = empty_symbol_table()
     for value in test_cases:
         with self.subTest(msg='value=' + str(value)):
             container = data_symbol_utils.container(value)
             # ACT #
             actual = restriction.is_satisfied_by(symbols, 'symbol_name', container)
             # ASSERT #
             self.assertIsNotNone(actual,
                                  'Result should denote failing validation')
Esempio n. 58
0
 def test_difference_in_relativity_root(self):
     symbols = empty_symbol_table()
     for relativity in _RELATIVITY_VARIANTS:
         for path_suffix in _PATH_SUFFIX_VARIANTS:
             test_case_descr = 'relativity:{}, path-suffix: {}'.format(relativity, type(path_suffix))
             path = PathDdvTestImpl(relativity, path_suffix)
             path_sdv = path_sdvs.constant(path)
             with self.subTest(msg=sut.equals_path_sdv.__name__ + ' :: ' + test_case_descr):
                 assertion = sut.equals_path_sdv(path_sdv)
                 assertion.apply_without_message(self, path_sdv)
             with self.subTest(msg=sut.matches_path_sdv.__name__ + ' :: ' + test_case_descr):
                 assertion = sut.matches_path_sdv(path,
                                                  equals_symbol_references__w_str_rendering(
                                                      path_sdv.references),
                                                  symbols)
                 assertion.apply_without_message(self, path_sdv)
Esempio n. 59
0
 def test_any__fail_WHEN_type_is_wo_str_rendering(self):
     # ARRANGE #
     test_cases = [
         file_matcher.ARBITRARY_SYMBOL_VALUE_CONTEXT,
         st_symbol_context.ARBITRARY_SYMBOL_VALUE_CONTEXT,
     ]
     restriction = sut.ArbitraryValueWStrRenderingRestriction.of_any()
     symbols = empty_symbol_table()
     for value in test_cases:
         with self.subTest(msg='value=' + str(value)):
             # ACT #
             actual = restriction.is_satisfied_by(symbols, 'symbol_name',
                                                  value.container)
             # ASSERT #
             self.assertIsNotNone(
                 actual, 'Result should denote failing validation')
Esempio n. 60
0
 def test_any__pass_WHEN_type_is_w_str_rendering(self):
     # ARRANGE #
     test_cases = [
         string.ARBITRARY_SYMBOL_VALUE_CONTEXT,
         path.ARBITRARY_SYMBOL_VALUE_CONTEXT,
         list_.ARBITRARY_SYMBOL_VALUE_CONTEXT,
     ]
     restriction = sut.ArbitraryValueWStrRenderingRestriction.of_any()
     symbols = empty_symbol_table()
     for value in test_cases:
         with self.subTest(msg='value=' + str(value)):
             # ACT #
             actual = restriction.is_satisfied_by(symbols, 'symbol_name',
                                                  value.container)
             # ASSERT #
             self.assertIsNone(actual)