def __init__(self, method_name): super().__init__(method_name) self.constructor = sut.actor() self.hds = fake_hds() self.pre_sds_env = InstructionEnvironmentPreSdsBuilder( self.hds, environ=dict(os.environ), ).build
def test_construct_and_get_sds(self): # ARRANGE # expected_hds = fake_hds() sds = fake_sds() # ACT # tcds = sut.TestCaseDs(expected_hds, sds) actual = tcds.sds # ASSERT # self.assertIs(actual, sds)
def fake_post_sds_environment() -> InstructionEnvironmentForPostSdsStep: sds = fake_sds() return InstructionEnvironmentForPostSdsStep( fake_hds(), ProcessExecutionSettings.with_empty_environ(), sds, TmpFileStorage(sds.internal_tmp_dir / 'instruction-dir', lambda path: DirFileSpaceThatDoNotCreateFiles(path)), SymbolTable.empty(), 2 ** 10, )
def test(self): hds_with_different_sub_dirs = fake_hds() expected_phase_2_step_2_names_set = { PhaseEnum.SETUP: psr.same_value_for_all_steps(step.ALL_SETUP_WITH_ENV_ARG, hds_with_different_sub_dirs), PhaseEnum.ACT: psr.same_value_for_all_steps(step.ALL_ACT_WITH_ENV_ARG, hds_with_different_sub_dirs), PhaseEnum.BEFORE_ASSERT: psr.same_value_for_all_steps(step.ALL_BEFORE_ASSERT_WITH_ENV_ARG, hds_with_different_sub_dirs), PhaseEnum.ASSERT: psr.same_value_for_all_steps(step.ALL_ASSERT_WITH_ENV_ARG, hds_with_different_sub_dirs), PhaseEnum.CLEANUP: psr.same_value_for_all_steps(step.ALL_CLEANUP_WITH_ENV_ARG, hds_with_different_sub_dirs), } actual_phase_2_step_2_names_set = psr.new_phase_enum_2_empty_dict() def recorder_for(phase_step: SimplePhaseStep): return psr.StepRecordingAction( phase_step, actual_phase_2_step_2_names_set, get_hds_from_instruction_environment) test_case = partial_test_case_with_instructions( [ psr.setup_phase_instruction_that_records_a_value_per_step( recorder_for), ], psr.act_phase_instructions_that_does_nothing(), [ psr. before_assert_phase_instruction_that_records_a_value_per_step( recorder_for) ], [ psr.assert_phase_instruction_that_records_a_value_per_step( recorder_for) ], [ psr.cleanup_phase_instruction_that_records_a_value_per_step( recorder_for) ], ) test__va( self, test_case, Arrangement(psr.actor_that_records_a_value_per_step( recorder_for, recorder_for_parse_step=psr.no_recording), hds=hds_with_different_sub_dirs), asrt.anything_goes()) self._check_result(expected_phase_2_step_2_names_set, actual_phase_2_step_2_names_set)
def __init__(self, hds: HomeDs = fake_hds(), environ: Optional[Dict[str, str]] = None, timeout_in_seconds: Optional[int] = 30, symbols: Optional[SymbolTable] = None, mem_buff_size: int = 2 ** 10, ): self._hds = hds self._environ = environ self._timeout_in_seconds = timeout_in_seconds self._symbols = symbol_table_from_none_or_value(symbols) self.mem_buff_size = mem_buff_size
def of_empty_env( hds: HomeDs = fake_hds(), timeout_in_seconds: Optional[int] = 30, symbols: Optional[SymbolTable] = None, mem_buff_size: int = 2 ** 10, ) -> 'InstructionEnvironmentPreSdsBuilder': return InstructionEnvironmentPreSdsBuilder( hds, dict(), timeout_in_seconds, symbols, mem_buff_size )
def new(hds: HomeDs = fake_hds(), environ: Dict[str, str] = None, sds: SandboxDs = fake_sds(), timeout_in_seconds: int = None, symbols: SymbolTable = None, mem_buff_size: int = 2 ** 10, ) -> 'InstructionEnvironmentPostSdsBuilder': return InstructionEnvironmentPostSdsBuilder( hds, sds, environ, timeout_in_seconds, symbols, mem_buff_size=mem_buff_size, )
def __init__(self, hds: HomeDs = fake_hds(), sds: SandboxDs = fake_sds(), environ: Optional[Dict[str, str]] = None, timeout_in_seconds: int = None, symbols: SymbolTable = None, get_paths_access_for_dir: Callable[[Path], DirFileSpace] = _default_get_tmp_space, mem_buff_size: int = 2 ** 10, ): self._hds = hds self._sds = sds self._environ = environ self._timeout_in_seconds = timeout_in_seconds self._symbols = symbol_table_from_none_or_value(symbols) self._get_paths_access_for_dir = get_paths_access_for_dir self.get_instr_tmp_file_space = lambda path: TmpFileStorage(path, get_paths_access_for_dir) self.mem_buff_size = mem_buff_size
def runTest(self): # ARRANGE # symbol_simple = Symbol('symbol_simple', 3, '3') symbol_complex = Symbol('symbol_complex', 7, '2 + 5') defined_symbols = self._symbol_table_with_string_values([ symbol_simple, symbol_complex, ]) the_instruction_environment = InstructionEnvironmentPostSdsBuilder.new( hds=fake_hds(), environ={}, sds=fake_sds(), symbols=defined_symbols, ).build_post_sds() cases = [ Case('single constant integer', '1', Expected(resolved_value=1, symbol_references=[])), Case( 'single symbol reference with simple contents', symbol_simple.ref_syntax, Expected(resolved_value=symbol_simple.value_int, symbol_references=[symbol_simple.symbol_reference])), Case( 'constant complex expression', surrounded_by_soft_quotes_str('1 + 2 * 3 * (2+2)'), Expected(resolved_value=1 + 2 * 3 * (2 + 2), symbol_references=[])), Case( 'single symbol reference with complex contents', symbol_complex.ref_syntax, Expected(resolved_value=symbol_complex.value_int, symbol_references=[symbol_complex.symbol_reference])), Case( 'mixed expression', surrounded_by_soft_quotes_str( '1 + {symbol_simple} * ({symbol_complex})'.format( symbol_simple=symbol_simple.ref_syntax, symbol_complex=symbol_complex.ref_syntax)), Expected(resolved_value=1 + symbol_simple.value_int * symbol_complex.value_int, symbol_references=[ symbol_simple.symbol_reference, symbol_complex.symbol_reference ])), ] environment = the_instruction_environment.path_resolving_environment_pre_or_post_sds for case in cases: syntax = IntegerAbsStx(StringLiteralAbsStx(case.source)) CHECKER.check__abs_stx__expr_parse_source_variants( self, syntax, defined_symbols, expectation=Expectation( symbol_references=equals_symbol_references__w_str_rendering( case.expected.symbol_references), sdv=ValidationAssertion(environment), ddv=_DDvAssertion(environment, case.expected.resolved_value), ), sub_test_identifiers={ 'case': case.name, })
def _new_environment() -> InstructionEnvironmentForPreSdsStep: hds = fake_hds() return InstructionEnvironmentPreSdsBuilder.of_empty_env(hds).build
def __init__(self, put: unittest.TestCase): self.put = put self.hds = fake_hds()