Beispiel #1
0
 def test_differs__rel_option_types__expected_has_super_set(self):
     expected = PathRelativityVariants(
         {RelOptionType.REL_ACT, RelOptionType.REL_HDS_CASE}, False)
     actual = PathRelativityVariants({RelOptionType.REL_ACT}, False)
     assertion = sut.path_relativity_variants_equals(expected)
     # ACT & ASSERT #
     assert_that_assertion_fails(assertion, actual)
Beispiel #2
0
 def test_equals(self):
     test_cases = [
         PathRelativityVariants(set(), False),
         PathRelativityVariants({RelOptionType.REL_ACT}, True),
     ]
     for variants in test_cases:
         restriction = PathAndRelativityRestriction(variants)
         with self.subTest():
             sut.equals__path_w_relativity(restriction).apply_without_message(self, restriction)
Beispiel #3
0
 def test_equals(self):
     test_cases = [
         PathAndRelativityRestriction(PathRelativityVariants(set(), False)),
         PathAndRelativityRestriction(PathRelativityVariants({RelOptionType.REL_ACT}, True)),
         ArbitraryValueWStrRenderingRestriction.of_any(),
         ArbitraryValueWStrRenderingRestriction.of_single(WithStrRenderingType.STRING),
         ArbitraryValueWStrRenderingRestriction.of_single(WithStrRenderingType.PATH),
         ArbitraryValueWStrRenderingRestriction([WithStrRenderingType.PATH, WithStrRenderingType.LIST]),
     ]
     for restriction in test_cases:
         with self.subTest():
             sut.equals(restriction).apply_without_message(self, restriction)
def src_rel_opt_conf(rel_option_types: AbstractSet[RelOptionType],
                     default_option: RelOptionType,
                     ) -> RelOptionsConfiguration:
    return RelOptionsConfiguration(PathRelativityVariants(
        set(rel_option_types),
        True),
        default_option)
Beispiel #5
0
def path_relativity_variants__src(
        phase_is_after_act: bool) -> PathRelativityVariants:
    rel_opts = set(RelOptionType)
    if not phase_is_after_act:
        rel_opts.remove(RelOptionType.REL_RESULT)

    return PathRelativityVariants(rel_opts, True)
Beispiel #6
0
 def visit_any(self, x: vr.ArbitraryValueWStrRenderingRestriction) -> Tuple[ValueType, DataTypeSdv]:
     if WithStrRenderingType.STRING in x.accepted:
         return _arbitrary_sdv__string()
     elif WithStrRenderingType.PATH in x.accepted:
         return _arbitrary_sdv__path(PathRelativityVariants(set(RelOptionType), True))
     elif WithStrRenderingType.LIST in x.accepted:
         return _arbitrary_sdv__list()
     else:
         raise TypeError('Unknown or empty list of {}: {}'.format(WithStrRenderingType, x.accepted))
Beispiel #7
0
 def __assertions_on_hypothetical_reference_to_sdv(self,
                                                   put: unittest.TestCase,
                                                   actual: PathSdv,
                                                   symbols: SymbolTable):
     restriction = PathAndRelativityRestriction(
         PathRelativityVariants(RelOptionType, True))
     container = PathSymbolValueContext.of_sdv(actual).container
     result = restriction.is_satisfied_by(symbols, 'hypothetical_symbol',
                                          container)
     put.assertIsNone(result, 'Result of hypothetical restriction on path')
Beispiel #8
0
def relativity_options(is_after_act_phase: bool) -> RelOptionArgumentConfiguration:
    accepted = [RelOptionType.REL_ACT,
                RelOptionType.REL_TMP,
                RelOptionType.REL_CWD]
    if is_after_act_phase:
        accepted.append(RelOptionType.REL_RESULT)
    variants = PathRelativityVariants(set(accepted), True)
    return RelOptionArgumentConfiguration(RelOptionsConfiguration(variants,
                                                                  RelOptionType.REL_CWD),
                                          _DIR_ARGUMENT.name,
                                          True)
Beispiel #9
0
    def runTest(self):
        test_cases = [
            PathRelativityVariants({rel_option_type}, accept_absolute)
            for accept_absolute in [False, True]
            for rel_option_type in RelOptionType
        ]

        for value in test_cases:
            with self.subTest(msg='RelOptionTypes={}, absolute={}'.format(
                    value.rel_option_types, value.absolute)):
                sut.path_relativity_variants_equals(value).apply_with_message(
                    self, value, 'Equals')
    def runTest(self):
        # ARRANGE #

        to_upper_transformer = StringTransformerSymbolContext.of_primitive(
            'TRANSFORMER_SYMBOL',
            string_transformers.to_uppercase(),
        )

        src_file = fs.File('src-file.txt', 'contents of source file')
        src_file_rel_conf = conf_rel_hds(RelHdsOptionType.REL_HDS_CASE)

        expected_contents = src_file.contents.upper()

        path_relativity_variants = PathRelativityVariants({src_file_rel_conf.relativity}, True)
        checker = integration_check.checker(RelOptionsConfiguration(path_relativity_variants,
                                                                    src_file_rel_conf.relativity))

        src_file_symbol = ConstantSuffixPathDdvSymbolContext(
            'SRC_FILE_SYMBOL',
            src_file_rel_conf.relativity,
            src_file.name,
            path_relativity_variants,
        )
        string_source_syntax = string_source_abs_stx.TransformedStringSourceAbsStx(
            string_source_abs_stx.StringSourceOfFileAbsStx(src_file_symbol.abstract_syntax),
            to_upper_transformer.abstract_syntax,
        )
        symbol_table = SymbolContext.symbol_table_of_contexts([
            src_file_symbol,
            to_upper_transformer,
        ])

        # ACT & ASSERT #
        checker.check__abs_stx__layouts__std_source_variants__wo_input(
            self,
            OptionallyOnNewLine(string_source_syntax),
            arrangement_w_tcds(
                symbols=symbol_table,
                hds_contents=src_file_rel_conf.populator_for_relativity_option_root__hds(
                    DirContents([src_file]))
            ),
            MultiSourceExpectation.of_prim__const(
                asrt_string_source.pre_post_freeze__matches_str__const(
                    expected_contents,
                    may_depend_on_external_resources=True,
                ),
                symbol_references=asrt.matches_sequence([
                    src_file_symbol.reference_assertion__path_or_string,
                    to_upper_transformer.reference_assertion,
                ]),
            ),
        )
 def test_path(self):
     # ARRANGE #
     expected_return_value = 69
     visitor = _VisitorThatRegisterClassOfVisitMethod(expected_return_value)
     # ACT #
     actual_return_value = visitor.visit(
         vr.PathAndRelativityRestriction(
             PathRelativityVariants(set(), False)))
     # ASSERT #
     self.assertEqual([vr.PathAndRelativityRestriction],
                      visitor.visited_classes, 'visited classes')
     self.assertEqual(expected_return_value, actual_return_value,
                      'return value')
Beispiel #12
0
 def test_symbol_references(self):
     # ARRANGE #
     expected_restriction = PathAndRelativityRestriction(
         PathRelativityVariants(
             {RelOptionType.REL_ACT, RelOptionType.REL_HDS_CASE}, True))
     symbol_name_of_rel_path = 'symbol_name_of_rel_path'
     symbol_name_of_path_suffix = 'symbol_name_of_path_suffix'
     restrictions_on_path_suffix_symbol = ReferenceRestrictionsOnDirectAndIndirect(
         ArbitraryValueWStrRenderingRestriction.of_any())
     expected_mandatory_references = [
         asrt_sym_ref.
         matches_symbol_reference_with_restriction_on_direct_target(
             symbol_name_of_rel_path,
             asrt_val_rest.equals__path_w_relativity(expected_restriction))
     ]
     symbol_ref_of_path = SymbolReference(
         symbol_name_of_rel_path,
         ReferenceRestrictionsOnDirectAndIndirect(expected_restriction))
     path_suffix_test_cases = [
         (
             path_part_sdvs.from_constant_str('file.txt'),
             [],
         ),
         (
             path_part_sdvs.from_string(
                 string_sdv_of_single_symbol_reference(
                     symbol_name_of_path_suffix,
                     restrictions_on_path_suffix_symbol)),
             [
                 asrt_sym_usage.matches_reference_2(
                     symbol_name_of_path_suffix,
                     asrt_w_str_rend_rest.matches__on_direct_and_indirect())
             ],
         ),
     ]
     for path_suffix_sdv, additional_expected_references in path_suffix_test_cases:
         path_sdv = sut.PathSdvRelSymbol(path_suffix_sdv,
                                         symbol_ref_of_path)
         # ACT #
         actual = path_sdv.references
         # ASSERT #
         expected_references = expected_mandatory_references + additional_expected_references
         assertion = asrt.matches_sequence(expected_references)
         assertion.apply_with_message(self, actual, 'symbol references')
Beispiel #13
0
 def test_fail__relative_paths(self):
     # ARRANGE #
     test_cases = [
         RelOptionType.REL_ACT,
         RelOptionType.REL_HDS_CASE,
     ]
     restriction = sut.PathAndRelativityRestriction(
         PathRelativityVariants({RelOptionType.REL_RESULT}, False))
     symbols = empty_symbol_table()
     for actual_relativity in test_cases:
         with self.subTest(msg='value=' + str(actual_relativity)):
             container = PathSymbolValueContext.of_rel_opt_and_suffix(
                 actual_relativity, 'base-name').container
             # ACT #
             actual = restriction.is_satisfied_by(symbols, 'symbol_name',
                                                  container)
             # ASSERT #
             self.assertIsNotNone(
                 actual, 'Result should denote failing validation')
Beispiel #14
0
def arg_config_with_all_accepted_and_default(
    default: RelOptionType
) -> RelOptionArgumentConfigurationWoSuffixRequirement:
    return RelOptionArgumentConfigurationWoSuffixRequirement(
        RelOptionsConfiguration(PathRelativityVariants(RelOptionType, True),
                                default), 'argument_syntax_name')
Beispiel #15
0
 def test_not_equals__same_type__different_accepted_relativity_variants(self):
     expected = PathAndRelativityRestriction(PathRelativityVariants({RelOptionType.REL_HDS_CASE}, False))
     actual = PathAndRelativityRestriction(PathRelativityVariants({RelOptionType.REL_ACT}, False))
     assert_that_assertion_fails(sut.equals(expected), actual)
Beispiel #16
0
                            ),
                            MultiSourceExpectation(
                                symbol_usages=SymbolContext.usages_assertion_of_contexts(file_matcher_case.arrangement),
                                execution=ExecutionExpectation(
                                    main_result=pfh_assertions.is_pass_of_fail(
                                        expectation_type is ExpectationType.NEGATIVE
                                    )
                                )
                            )
                        )


EXPECTED_ACCEPTED_PATH_RELATIVITY_VARIANTS = PathRelativityVariants(
    {RelOptionType.REL_CWD,
     RelOptionType.REL_HDS_CASE,
     RelOptionType.REL_HDS_ACT,
     RelOptionType.REL_ACT,
     RelOptionType.REL_TMP},
    True)

ACCEPTED_REL_OPT_CONFIGURATIONS = (
        list(map(rel_opt_conf.conf_rel_any, EXPECTED_ACCEPTED_PATH_RELATIVITY_VARIANTS.rel_option_types)) +

        [rel_opt_conf.symbol_conf_rel_any(RelOptionType.REL_TMP,
                                          'symbol_name',
                                          EXPECTED_ACCEPTED_PATH_RELATIVITY_VARIANTS)] +

        [rel_opt_conf.default_conf_rel_any(RelOptionType.REL_CWD)]
)

UNACCEPTED_REL_OPT_CONFIGURATIONS = [
Beispiel #17
0
                 RelOptionArgumentConfigurationWoSuffixRequirement,
                 source_file_path: Optional[Path] = None):
        self.source = source
        self.rel_option_argument_configuration = rel_option_argument_configuration
        self.source_file_path = source_file_path

    def for_path_suffix_required(self, value: bool) -> Arrangement:
        return Arrangement(
            self.source,
            self.rel_option_argument_configuration.config_for(value),
            self.source_file_path)


ARBITRARY_REL_OPT_ARG_CONF = RelOptionArgumentConfigurationWoSuffixRequirement(
    RelOptionsConfiguration(
        PathRelativityVariants({RelOptionType.REL_ACT}, True),
        RelOptionType.REL_ACT), 'argument_syntax_name')

ARG_CONFIG_FOR_ALL_RELATIVITIES = RelOptionArgumentConfigurationWoSuffixRequirement(
    RelOptionsConfiguration(PathRelativityVariants(RelOptionType, True),
                            RelOptionType.REL_HDS_CASE),
    'argument_syntax_name')


def arg_config_with_all_accepted_and_default(
    default: RelOptionType
) -> RelOptionArgumentConfigurationWoSuffixRequirement:
    return RelOptionArgumentConfigurationWoSuffixRequirement(
        RelOptionsConfiguration(PathRelativityVariants(RelOptionType, True),
                                default), 'argument_syntax_name')
Beispiel #18
0
def all_rel_options_config(default: RelOptionType) -> RelOptionsConfiguration:
    return RelOptionsConfiguration(
        PathRelativityVariants(ALL_REL_OPTIONS, True), default)
Beispiel #19
0
 def test_differs__absolute(self):
     expected = PathRelativityVariants({RelOptionType.REL_ACT}, False)
     actual = PathRelativityVariants({RelOptionType.REL_ACT}, True)
     assertion = sut.path_relativity_variants_equals(expected)
     # ACT & ASSERT #
     assert_that_assertion_fails(assertion, actual)
Beispiel #20
0
def rel_opts_conf_of_single(default_relativity: RelOptionType) -> RelOptionsConfiguration:
    return RelOptionsConfiguration(
        PathRelativityVariants({default_relativity}, False),
        default_relativity,
    )
Beispiel #21
0
class StringTransformerParser(TypeValueParser):
    def parse(
        self,
        fs_location_info: FileSystemLocationInfo,
        token_parser: TokenParser,
    ) -> SymbolDependentValue:
        return parse_string_transformer.parsers().full.parse_from_token_parser(
            token_parser)


class ProgramParser(TypeValueParser):
    _PARSER = parse_program.program_parser(must_be_on_current_line=False, )

    def parse(
        self,
        fs_location_info: FileSystemLocationInfo,
        token_parser: TokenParser,
    ) -> SymbolDependentValue:
        return self._PARSER.parse_from_token_parser(token_parser)


REL_OPTIONS_CONFIGURATION = RelOptionsConfiguration(
    PathRelativityVariants(frozenset(RelOptionType), True),
    RelOptionType.REL_CWD)

REL_OPTION_ARGUMENT_CONFIGURATION = RelOptionArgumentConfiguration(
    REL_OPTIONS_CONFIGURATION,
    syntax_elements.PATH_SYNTAX_ELEMENT.singular_name,
    syntax.PATH_SUFFIX_IS_REQUIRED,
)
        return self[1]

    @property
    def argument(self) -> a.Named:
        return a.Named(self.argument_syntax_name)


def arg_config_with_name(new_syntax_element_name: str,
                         existing: RelOptionArgumentConfiguration) -> RelOptionArgumentConfiguration:
    return RelOptionArgumentConfiguration(existing.options,
                                          new_syntax_element_name,
                                          existing.path_suffix_is_required)


RELATIVITY_VARIANTS_FOR_FILE_CREATION = PathRelativityVariants({RelOptionType.REL_ACT,
                                                                RelOptionType.REL_TMP,
                                                                RelOptionType.REL_CWD},
                                                               False)

REL_OPTIONS_FOR_FILE_CREATION = RelOptionsConfiguration(RELATIVITY_VARIANTS_FOR_FILE_CREATION,
                                                        RelOptionType.REL_CWD)


def argument_configuration_for_file_creation(argument_syntax_element_name: str) -> RelOptionArgumentConfiguration:
    return RelOptionArgumentConfiguration(REL_OPTIONS_FOR_FILE_CREATION,
                                          argument_syntax_element_name,
                                          True)


RELATIVITY_VARIANTS_FOR_SOURCE_FILES__PRE_ACT = PathRelativityVariants({RelOptionType.REL_HDS_CASE,
                                                                        RelOptionType.REL_HDS_ACT,
                                                                        RelOptionType.REL_ACT,
Beispiel #23
0
def _path_relativity_variants_with(
        accepted: RelOptionType) -> PathRelativityVariants:
    return PathRelativityVariants({accepted}, False)
Beispiel #24
0
]

ARBITRARY_ALLOWED_SRC_FILE_RELATIVITY = conf_rel_non_hds(
    RelNonHdsOptionType.REL_TMP)
ARBITRARY_ALLOWED_DST_FILE_RELATIVITY = conf_rel_non_hds(
    RelNonHdsOptionType.REL_TMP)

ALLOWED_DST_FILE_RELATIVITIES = [
    conf_rel_non_hds(RelNonHdsOptionType.REL_ACT),
    conf_rel_non_hds(RelNonHdsOptionType.REL_TMP),
    conf_rel_non_hds(RelNonHdsOptionType.REL_CWD),
    default_conf_rel_non_hds(RelNonHdsOptionType.REL_CWD),
]

ACCEPTED_DST_RELATIVITY_VARIANTS = PathRelativityVariants(
    {RelOptionType.REL_ACT, RelOptionType.REL_TMP, RelOptionType.REL_CWD},
    absolute=False,
)


def accepted_src_file_relativities(
        phase_is_after_act: bool) -> Sequence[RelativityOptionConfiguration]:
    return (ALLOWED_SRC_FILE_RELATIVITIES__BEFORE_ACT +
            [conf_rel_sds(RelSdsOptionType.REL_RESULT)] if phase_is_after_act
            else ALLOWED_SRC_FILE_RELATIVITIES__BEFORE_ACT)


def accepted_non_hds_source_relativities(
        phase_is_after_act: bool) -> Set[RelNonHdsOptionType]:
    if phase_is_after_act:
        return set(RelNonHdsOptionType)
    else:
Beispiel #25
0
from exactly_lib.impls.types.parse.shell_syntax import SHELL_KEYWORD
from exactly_lib.tcfs.path_relativity import PathRelativityVariants, RelOptionType
from exactly_lib.type_val_deps.types.path.rel_opts_configuration import RelOptionArgumentConfiguration, \
    RelOptionsConfiguration

SHELL_COMMAND_MARKER = SHELL_KEYWORD

REL_OPTIONS_CONFIGURATION = RelOptionsConfiguration(
    PathRelativityVariants(
        {
            RelOptionType.REL_HDS_CASE,
            RelOptionType.REL_HDS_ACT,
            RelOptionType.REL_ACT,
            RelOptionType.REL_TMP,
            RelOptionType.REL_CWD,
        },
        absolute=True),
    default_option=RelOptionType.REL_HDS_ACT)


def relativity_configuration_of_action_to_check(
        argument_syntax_name: str) -> RelOptionArgumentConfiguration:
    return RelOptionArgumentConfiguration(
        REL_OPTIONS_CONFIGURATION,
        argument_syntax_name=argument_syntax_name,
        path_suffix_is_required=True)
Beispiel #26
0
 def test_not_equals__different__types__one_is_path_relativity_variants(self):
     expected = PathAndRelativityRestriction(PathRelativityVariants({RelOptionType.REL_HDS_CASE}, False))
     actual = ArbitraryValueWStrRenderingRestriction.of_any()
     assert_that_assertion_fails(sut.equals(expected), actual)
Beispiel #27
0
def _relativity_restriction(
        rel_option_types: set,
        absolute_is_valid: bool) -> PathAndRelativityRestriction:
    return PathAndRelativityRestriction(
        PathRelativityVariants(rel_option_types, absolute_is_valid))
Beispiel #28
0
from exactly_lib.definitions.entity import syntax_elements
from exactly_lib.tcfs.path_relativity import RelOptionType, PathRelativityVariants
from exactly_lib.type_val_deps.types.path.rel_opts_configuration import RelOptionsConfiguration, \
    RelOptionArgumentConfiguration

RELATIVITIES__READ__BEFORE_ACT = frozenset(
    set(RelOptionType).difference({RelOptionType.REL_RESULT}))
RELATIVITIES__READ__AFTER_ACT = frozenset(set(RelOptionType))

RELATIVITY_VARIANTS__READ__BEFORE_ACT = PathRelativityVariants.of_frozen_set(
    RELATIVITIES__READ__BEFORE_ACT, True)
RELATIVITY_VARIANTS__READ__AFTER_ACT = PathRelativityVariants.of_frozen_set(
    RELATIVITIES__READ__AFTER_ACT, True)


def relativity_variants(phase_is_after_act: bool) -> PathRelativityVariants:
    return (RELATIVITY_VARIANTS__READ__AFTER_ACT
            if phase_is_after_act else RELATIVITY_VARIANTS__READ__BEFORE_ACT)


ALL_REL_OPTIONS = set(RelOptionType) - {RelOptionType.REL_RESULT}
ALL_HDS_REL_OPTIONS = {RelOptionType.REL_HDS_CASE, RelOptionType.REL_HDS_ACT}

ALL_REL_OPTION_VARIANTS = PathRelativityVariants(ALL_REL_OPTIONS, True)

PATH_ASSERTION_RELATIVITIES = PathRelativityVariants(ALL_REL_OPTIONS, True)

PATH_ASSERTION_REL_OPTS_CONF = RelOptionsConfiguration(
    PATH_ASSERTION_RELATIVITIES, RelOptionType.REL_CWD)

Beispiel #29
0
import unittest

from exactly_lib.tcfs.path_relativity import PathRelativityVariants, RelOptionType
from exactly_lib.test_case.phases.act.instruction import ActPhaseInstruction

PATH_RELATIVITY_VARIANTS_FOR_FILE_TO_RUN = PathRelativityVariants(
    {
        RelOptionType.REL_HDS_ACT, RelOptionType.REL_HDS_CASE,
        RelOptionType.REL_ACT, RelOptionType.REL_TMP, RelOptionType.REL_CWD
    },
    absolute=True)


def assert_is_list_of_act_phase_instructions(put: unittest.TestCase, x):
    put.assertIsInstance(
        x, list,
        'Invalid test input: Expecting list of ActPhaseInstruction:s. Found: '
        + str(type(x)))
    i = 0
    for e in x:
        put.assertIsInstance(
            e, ActPhaseInstruction,
            'Invalid test input: Element [%d]. Expecting an ActPhaseInstruction:s. Found: %s'
            % (i, type(e)))
        i += 1
Beispiel #30
0
from exactly_lib.tcfs.path_relativity import RelOptionType, PathRelativityVariants, DEPENDENCY_DICT, \
    DirectoryStructurePartition, RelHdsOptionType, RelNonHdsOptionType
from exactly_lib_test.impls.types.test_resources import relativity_options as rel_opt_conf


def path_relativity_variants__src(
        phase_is_after_act: bool) -> PathRelativityVariants:
    rel_opts = set(RelOptionType)
    if not phase_is_after_act:
        rel_opts.remove(RelOptionType.REL_RESULT)

    return PathRelativityVariants(rel_opts, True)


PATH_RELATIVITY_VARIANTS__DST = PathRelativityVariants(
    DEPENDENCY_DICT[DirectoryStructurePartition.NON_HDS] -
    {RelOptionType.REL_RESULT},
    False,
)
ARBITRARY_LEGAL_RELATIVITY__SRC = RelOptionType.REL_HDS_CASE
ARBITRARY_LEGAL_RELATIVITY__SRC__HDS = RelHdsOptionType.REL_HDS_CASE
ARBITRARY_LEGAL_RELATIVITY__DST = RelOptionType.REL_ACT
ARBITRARY_LEGAL_RELATIVITY__DST__NON_HDS = RelNonHdsOptionType.REL_ACT
ARBITRARY_SRC_REL_OPT = rel_opt_conf.conf_rel_hds(RelHdsOptionType.REL_HDS_ACT)
ARBITRARY_DST_REL_OPT = rel_opt_conf.conf_rel_non_hds(
    RelNonHdsOptionType.REL_ACT)
DEFAULT_SRC_REL_OPT = rel_opt_conf.default_conf_rel_hds(
    RelHdsOptionType.REL_HDS_CASE)
DEFAULT_DST_REL_OPT = rel_opt_conf.default_conf_rel_non_hds(
    RelNonHdsOptionType.REL_CWD)