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 new_from_pre_sds( environment: InstructionEnvironmentForPreSdsStep, sds: SandboxDs = fake_sds(), ) -> 'InstructionEnvironmentPostSdsBuilder': return InstructionEnvironmentPostSdsBuilder( environment.hds, sds, environment.proc_exe_settings.environ, environment.proc_exe_settings.timeout_in_seconds, environment.symbols, mem_buff_size=environment.mem_buff_size, )
def test_populate_tcds(self): # ARRANGE # populator = sut.empty() expectation = f_asrt.dir_is_empty() sds = fake_sds() with home_directory_structure() as hds: tcds = TestCaseDs(hds, sds) # ACT # populator.populate_tcds(tcds) # ASSERT # expectation.apply_with_message(self, hds.case_dir, 'contents of HDS/case dir')
def test_populate_hds_or_sds(self): # ARRANGE # expected_dir_contents = fs.DirContents([fs.File('a-file-name.txt', 'the file contents')]) populator = sut.hds_case_dir_contents(expected_dir_contents) expectation = f_asrt.dir_contains_exactly(expected_dir_contents) sds = fake_sds() with home_directory_structure() as hds: tcds = TestCaseDs(hds, sds) # ACT # populator.populate_tcds(tcds) # ASSERT # expectation.apply_with_message(self, hds.case_dir, 'contents of HDS/case dir')
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 test_two_populators_populate_tcds(self): # ARRANGE # expected_dir_contents = fs.DirContents([self.first_file, self.second_file]) first_populator = sut.hds_case_dir_contents(fs.DirContents([self.first_file])) second_populator = sut.hds_case_dir_contents(fs.DirContents([self.second_file])) populator = sut.multiple([first_populator, second_populator]) expectation = f_asrt.dir_contains_exactly(expected_dir_contents) sds = fake_sds() with home_directory_structure() as hds: tcds = TestCaseDs(hds, sds) # ACT # populator.populate_tcds(tcds) # ASSERT # expectation.apply_with_message(self, hds.case_dir, 'contents of HDS/case dir')
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, })
section_name=self._SECTION_NAME + 'unexpected', ), expected_value=sut.error_info_matches( section_name=asrt.equals(self._SECTION_NAME)), ), ] for case in cases: with self.subTest(case.name): assert_that_assertion_fails(case.expected_value, case.input_value) _FULL_EXE_RESULT__ARBITRARY = full_exe_result.new_skipped() _FULL_EXE_RESULT__SKIPPED = full_exe_result.new_skipped() _FULL_EXE_RESULT__PASS = full_exe_result.new_pass(fake_sds(), ActionToCheckOutcome(0)) _ERROR_INFO__WITH_DESCRIPTION = ErrorInfo( description=error_description.of_constant_message('error info message')) class TestResultMatches(unittest.TestCase): _SECTION_NAME = 'a section name' _AN_ACCESS_ERROR_TYPE = test_case_processing.AccessErrorType.FILE_ACCESS_ERROR def test_matches(self): cases = [ NEA( 'default/skipped', actual=test_case_processing.new_executed(