コード例 #1
0
    def runTest(self):
        expected_contents = 'expected-contents'
        resolving_env = PathResolvingEnvironmentPreOrPostSds(fake_tcds())

        sdv = self._sdv_expecting_equals(expected_contents)
        adv = sdv.resolve(resolving_env.symbols).value_of_any_dependency(resolving_env.tcds)

        for actual_contents in [expected_contents, expected_contents + '-unexpected']:
            expected_result = actual_contents == expected_contents
            expected_matching_result = asrt_matching_result.matches_value(expected_result)
            with self.subTest(expected_result=expected_result):
                model_w_ext_deps = model_constructor.of_str(
                    self,
                    actual_contents,
                    may_depend_on_external_resources=True,
                )
                with tmp_dir() as dir_space_dir__matcher:
                    matcher = adv.primitive(self._app_env(dir_space_dir__matcher, 'matcher-path'))
                    with tmp_dir() as dir_space_dir__model:
                        model = model_w_ext_deps(FullResolvingEnvironment(
                            resolving_env.symbols,
                            resolving_env.tcds,
                            self._app_env(dir_space_dir__model, 'model-path')
                        ))
                        # ACT #
                        matching_result_1st = matcher.matches_w_trace(model)
                        matching_result_2nd = matcher.matches_w_trace(model)
                        # ASSERT #
                        expected_matching_result.apply_with_message(self, matching_result_1st, '1st')
                        expected_matching_result.apply_with_message(self, matching_result_2nd, '2nd')
コード例 #2
0
 def test_instruction_validation_step(self):
     # ARRANGE #
     with tmp_dir.tmp_dir() as root_dir:
         factory = sut.PhaseTmpFileSpaceFactory(root_dir)
         cases = [
             NameAndValue(phase_identifier.BEFORE_ASSERT.identifier,
                          (phase_identifier.BEFORE_ASSERT, 1)),
             NameAndValue(phase_identifier.CLEANUP.identifier,
                          (phase_identifier.CLEANUP, 2)),
             NameAndValue(
                 phase_identifier.SETUP.identifier,
                 (phase_identifier.SETUP, 2),
             ),
         ]
         for case in cases:
             with self.subTest(case.name):
                 expected_dir = (
                     root_dir /
                     sut.PhaseTmpFileSpaceFactory.VALIDATION_SUB_DIR /
                     _expected_phase_dir(case.value[0]) /
                     _expected_instruction_dir(case.value[1]))
                 # ACT & ASSERT #
                 _check(
                     self,
                     expected_dir,
                     factory.instruction__validation(
                         case.value[0], case.value[1]),
                 )
コード例 #3
0
ファイル: file_properties.py プロジェクト: emilkarlen/exactly
def dir_with_symlink_to_existing_dir() -> pathlib.Path:
    with tmp_dir(
            DirContents([
                Dir.empty('existing-dir'),
                sym_link('existing-symlink', 'existing-dir')
            ])) as dir_path:
        yield dir_path / 'existing-symlink'
コード例 #4
0
ファイル: atc_execution.py プロジェクト: emilkarlen/exactly
def _check_contents_of_stdin_for_setup_settings(put: unittest.TestCase,
                                                setup_settings: SetupSettingsBuilder,
                                                expected_contents_of_stdin: str) -> PartialExeResult:
    """
    Tests contents of stdin by executing a Python program that stores
    the contents of stdin in a file.
    """
    with tmp_dir() as tmp_dir_path:
        with preserved_cwd():
            # ARRANGE #
            output_file_path = tmp_dir_path / 'output.txt'
            python_program_file = fs.File('program.py', _python_program_that_prints_stdin_to(output_file_path))
            python_program_file.write_to(tmp_dir_path)
            executor_that_records_contents_of_stdin = _AtcThatExecutesPythonProgramFile(
                tmp_dir_path / 'program.py')
            parser = ActorForConstantAtc(
                executor_that_records_contents_of_stdin)
            test_case = _empty_test_case()
            # ACT #
            result = _execute(parser, test_case, setup_settings)
            # ASSERT #
            file_checker = FileChecker(put)
            file_checker.assert_file_contents(output_file_path,
                                              expected_contents_of_stdin)
            return result
コード例 #5
0
 def test_new_path_as_existing_dir(self):
     # ARRANGE #
     for case in _root_dir_cases():
         with self.subTest(case.name):
             with tmp_dir() as existing_dir_path:
                 space_root_dir = case.value(existing_dir_path)
                 # ACT
                 space = sut.DirFileSpaceAsDirCreatedOnDemand(
                     space_root_dir,
                     FileNamesConfig('---', iter(['1', '2', '3', '4']),
                                     iter([])),
                 )
                 file_1 = space.new_path()
                 dir_2 = space.new_path_as_existing_dir()
                 file_3 = space.new_path('three')
                 dir_4 = space.new_path_as_existing_dir('four')
                 # ASSERT #
                 self._assert_is_non_existing_file(space_root_dir / '1',
                                                   file_1)
                 self._assert_is_existing_dir(space_root_dir / '2', dir_2)
                 self._assert_is_non_existing_file(
                     space_root_dir / '3---three', file_3)
                 self._assert_is_existing_dir(space_root_dir / '4---four',
                                              dir_4)
                 self._assert_num_files_in_dir(space_root_dir,
                                               expected_number_of_files=2)
コード例 #6
0
def dir_file_space_for_single_usage_getter(
        put: unittest.TestCase,
        message_builder: MessageBuilder) -> ContextManager[DirFileSpace]:
    with tmp_dir.tmp_dir() as storage_dir:
        yield TmpFileSpaceThatAllowsSinglePathGeneration(
            put, storage_dir, 'path-name',
            message_builder.apply('dir-file-space'))
コード例 #7
0
ファイル: path_type.py プロジェクト: emilkarlen/exactly
 def test(self):
     with tmp_dir() as abs_path_of_dir_containing_last_file_base_name:
         fs_location_info = FileSystemLocationInfo(
             FileLocationInfo(
                 abs_path_of_dir_containing_last_file_base_name))
         instruction_argument = src2(ValueType.PATH, 'name',
                                     '{rel_source_file} component')
         for source in equivalent_source_variants__with_source_check__consume_last_line(
                 self, instruction_argument):
             expected_path_sdv = path_sdvs.constant(
                 path_ddvs.rel_abs_path(
                     abs_path_of_dir_containing_last_file_base_name,
                     path_ddvs.constant_path_part('component')))
             expected_symbol_value = PathSymbolValueContext.of_sdv(
                 expected_path_sdv)
             expected_symbol = PathSymbolContext('name',
                                                 expected_symbol_value)
             INSTRUCTION_CHECKER.check(
                 self, source,
                 Arrangement.phase_agnostic(
                     fs_location_info=fs_location_info),
                 Expectation.phase_agnostic(
                     symbol_usages=asrt.matches_singleton_sequence(
                         expected_symbol.assert_matches_definition_of_sdv),
                     symbols_after_main=assert_symbol_table_is_singleton(
                         'name', expected_symbol_value.
                         assert_matches_container_of_sdv)))
コード例 #8
0
    def test_that_value_set_in_first_case_does_not_leak_to_second_case(self):
        # ARRANGE #

        containing_suite_file = File('test.suite', SUITE_WITH_CASES)
        suite_and_case_files = DirContents([
            containing_suite_file,
            CASE_1_FILE,
            CASE_2_FILE,
        ])

        case_processors = [
            NameAndValue('processor_that_should_not_pollute_current_process',
                         processors.new_processor_that_should_not_pollute_current_process),
            NameAndValue('processor_that_is_allowed_to_pollute_current_process',
                         processors.new_processor_that_is_allowed_to_pollute_current_process),
        ]
        with tmp_dir(suite_and_case_files) as tmp_dir_path:
            suite_file_path = tmp_dir_path / containing_suite_file.file_name

            for case_processor_case in case_processors:
                with self.subTest(case_processor_case.name):
                    registry = tr.Registry()
                    processor = new_processor_with_no_symbols(registry,
                                                              case_processor_case.value)
                    # ACT #

                    return_value = processor.process(suite_file_path, StringStdOutFiles().stdout_files)

                    # ASSERT #

                    self.assertEqual(ExecutionTracingRootSuiteReporter.VALID_SUITE_EXIT_CODE,
                                     return_value,
                                     'Sanity check of result indicator')
                    self.assertFalse(registry.observation)
コード例 #9
0
    def runTest(self):
        # ARRANGE #
        copy_stdin_to_stdout_program = [
            sys.executable, PY_ARG_FOR_EXECUTING_SOURCE_ON_COMMAND_LINE,
            py_programs.py_pgm_that_copies_stdin_to_stdout()
        ]

        stdin_contents = 'the contents of stdin'
        buff_size = len(stdin_contents) * 2
        with tmp_dir() as tmp_dir_path:
            stdin_path = tmp_dir_path / 'stdin'
            stdout_path = tmp_dir_path / 'stdout'
            stdin_path_getter = _GetSingleConstPath(self, stdin_path)
            stdout_path_getter = _GetSingleConstPath(self, stdout_path)
            # ACT #
            with sut.SpooledTextFile(buff_size,
                                     stdin_path_getter.get_path) as f_stdin:
                f_stdin.write(stdin_contents)
                _seek_to_start(f_stdin)
                with sut.SpooledTextFile(
                        buff_size, stdout_path_getter.get_path) as f_stdout:
                    subprocess.run(args=copy_stdin_to_stdout_program,
                                   stdin=f_stdin,
                                   stdout=f_stdout,
                                   stderr=subprocess.DEVNULL)
            # ASSERT #
            contents_of_stdout_file = misc_utils.contents_of(stdout_path)
            self.assertEqual(stdin_contents, contents_of_stdout_file)
コード例 #10
0
ファイル: file_utils.py プロジェクト: emilkarlen/exactly
 def test_new_path_as_existing_dir(self):
     # ARRANGE #
     cases = [
         NameAndValue('existing root dir',
                      lambda existing_dir: existing_dir
                      ),
         NameAndValue('non existing root dir',
                      lambda existing_dir: existing_dir / 'non-existing-root-dir-component'
                      ),
     ]
     for case in cases:
         with self.subTest(case.name):
             with tmp_dir() as existing_dir_path:
                 space_root_dir = case.value(existing_dir_path)
                 # ACT
                 space = sut.TmpDirFileSpaceAsDirCreatedOnDemand(space_root_dir)
                 file_1 = space.new_path()
                 dir_2 = space.new_path_as_existing_dir()
                 file_3 = space.new_path()
                 dir_4 = space.new_path_as_existing_dir()
                 # ASSERT #
                 self._assert_is_non_existing_file(space_root_dir / '01',
                                                   file_1)
                 self._assert_is_existing_dir(space_root_dir / '02',
                                              dir_2)
                 self._assert_is_non_existing_file(space_root_dir / '03',
                                                   file_3)
                 self._assert_is_existing_dir(space_root_dir / '04',
                                              dir_4)
                 self._assert_num_files_in_dir(space_root_dir,
                                               expected_number_of_files=2)
コード例 #11
0
    def test_that_value_set_in_first_case_does_not_leak_to_second_case(self):
        # ARRANGE #

        containing_suite_file = File('test.suite', SUITE_WITH_CASES)
        suite_and_case_files = DirContents([
            containing_suite_file,
            CASE_1_FILE,
            CASE_2_FILE,
        ])

        case_processors = [
            NameAndValue('processor_that_should_not_pollute_current_process',
                         processors.new_processor_that_should_not_pollute_current_process),
            NameAndValue('processor_that_is_allowed_to_pollute_current_process',
                         processors.new_processor_that_is_allowed_to_pollute_current_process),
        ]
        with tmp_dir(suite_and_case_files) as tmp_dir_path:
            suite_file_path = tmp_dir_path / containing_suite_file.file_name

            for case_processor_case in case_processors:
                with self.subTest(case_processor_case.name):
                    registry = tr.Registry()
                    processor = new_processor_with_no_env_vars(registry,
                                                               case_processor_case.value)
                    # ACT #

                    return_value = processor.process(suite_file_path, StringStdOutFiles().reporting_environment)

                    # ASSERT #

                    self.assertEqual(ExecutionTracingRootSuiteReporter.VALID_SUITE_EXIT_CODE,
                                     return_value,
                                     'Sanity check of result indicator')
                    self.assertFalse(registry.observation)
コード例 #12
0
    def test_dir_separator_in_name_suffixes_is_replaced_with_non_separator(
            self):
        def f(template: str) -> str:
            return template.format(dir_sep=os.sep)

        # ARRANGE #
        for case in _root_dir_cases():
            with self.subTest(case.name):
                with tmp_dir() as existing_dir_path:
                    space_root_dir = case.value(existing_dir_path)
                    root_space = sut.DirFileSpaceAsDirCreatedOnDemand(
                        space_root_dir,
                        FileNamesConfig('--', iter(['a', 'b']),
                                        iter([
                                            iter(['1', '2']),
                                        ])),
                    )
                    # AC & ASSERT #

                    sub_dir_space_1 = root_space.sub_dir_space(
                        f('{dir_sep}A{dir_sep}'))

                    path_1_1 = sub_dir_space_1.new_path(f('1{dir_sep}1'))
                    path_1_2 = sub_dir_space_1.new_path_as_existing_dir(
                        f('1{dir_sep}2'))

                    self.assertEqual(
                        space_root_dir / 'a--_A_' / '1--1_1',
                        path_1_1,
                    )
                    self.assertEqual(
                        space_root_dir / 'a--_A_' / '2--1_2',
                        path_1_2,
                    )
コード例 #13
0
 def test_mem_buff_size_SHOULD_be_propagated_to_every_instruction_after_conf_phase(
         self):
     # ARRANGE #
     with tmp_dir() as tmp_dir_path:
         expected_mem_buff_size = 72
         actual_recordings = {}
         recorder_builder = PropertyRecorderBuilder(get_mem_buff_size,
                                                    actual_recordings)
         test_case_builder = builder_of_test_case_that_records_property_of_env_for_each_step_of_partial_execution(
             recorder_builder)
         test_case = test_case_builder.build()
         actor = actor_that_records_property_of_env_for_each_step_post_sds(
             recorder_builder)
         configuration_builder = ConfigurationBuilder(
             tmp_dir_path, tmp_dir_path, NameAndValue('the actor', actor))
         arrangement = execution_check.Arrangement(
             test_case,
             configuration_builder,
             mem_buff_size=expected_mem_buff_size)
         expectation = execution_check.Expectation(
             full_result=asrt_full_result.is_pass())
         # ACT & ASSERT #
         execution_check.check(self, arrangement, expectation)
         # ASSERT #
         expected_recordings = dict.fromkeys(
             ALL_SETUP_WITH_ENV_ARG + ALL_ACT_POST_SDS +
             ALL_BEFORE_ASSERT_WITH_ENV_ARG + ALL_ASSERT_WITH_ENV_ARG +
             ALL_CLEANUP_WITH_ENV_ARG, expected_mem_buff_size)
         self.assertDictEqual(expected_recordings, actual_recordings)
コード例 #14
0
ファイル: atc_execution.py プロジェクト: emilkarlen/exactly
def _check_contents_of_stdin_for_setup_settings(
        put: unittest.TestCase, settings_handler: MkSetupSettingsHandler,
        expected_contents_of_stdin: str) -> PartialExeResult:
    """
    Tests contents of stdin by executing a Python program that stores
    the contents of stdin in a file.
    """
    with tmp_dir() as tmp_dir_path:
        with preserved_cwd():
            # ARRANGE #
            output_file_path = tmp_dir_path / 'output.txt'
            python_program_file = fs.File(
                'logic_symbol_utils.py',
                _python_program_that_prints_stdin_to(output_file_path))
            python_program_file.write_to(tmp_dir_path)
            executor_that_records_contents_of_stdin = _AtcThatExecutesPythonProgramFile(
                tmp_dir_path / 'logic_symbol_utils.py')
            parser = ActorForConstantAtc(
                executor_that_records_contents_of_stdin)
            test_case = _empty_test_case()
            # ACT #
            result = _execute(parser, test_case, settings_handler)
            # ASSERT #
            file_checker = FileChecker(put)
            file_checker.assert_file_contents(output_file_path,
                                              expected_contents_of_stdin)
            return result
コード例 #15
0
ファイル: file_utils.py プロジェクト: emilkarlen/exactly
 def test_non_existing_root_dir_SHOULD_not_be_created_when_object_is_constructed(self):
     # ARRANGE #
     with tmp_dir() as existing_dir_path:
         space_root_dir = existing_dir_path / 'non-existing-root'
         # ACT #
         sut.TmpDirFileSpaceAsDirCreatedOnDemand(space_root_dir)
         # ASSERT #
         self.assertFalse(space_root_dir.exists())
コード例 #16
0
 def test_invalid_executable(self):
     with tmp_dir() as tmp_dir_path:
         executor = sut.ExecutorThatStoresResultInFilesInDir(with_no_timeout())
         result = executor.execute(tmp_dir_path,
                                   executables.for_executable_file(tmp_dir_path / 'non-existing-program')
                                   )
         self.assertFalse(result.is_success,
                          'Result should indicate failure')
コード例 #17
0
ファイル: file_utils.py プロジェクト: emilkarlen/exactly
 def test_existing_root_dir_SHOULD_not_be_created_when_file_is_demanded(self):
     # ARRANGE #
     with tmp_dir() as existing_dir_path:
         space_root_dir = existing_dir_path
         # ACT
         space = sut.TmpDirFileSpaceAsDirCreatedOnDemand(space_root_dir)
         space.new_path()
         # ASSERT #
         self.assertTrue(space_root_dir.is_dir())
コード例 #18
0
ファイル: atc_execution.py プロジェクト: emilkarlen/exactly
 def test_WHEN_stdin_set_to_file_THEN_it_SHOULD_consist_of_contents_of_this_file(self):
     file_to_redirect = fs.File('redirected-to-stdin.txt', 'contents of file to redirect')
     with tmp_dir(fs.DirContents([file_to_redirect])) as abs_tmp_dir_path:
         absolute_name_of_file_to_redirect = abs_tmp_dir_path / 'redirected-to-stdin.txt'
         setup_settings = setup.default_settings()
         setup_settings.stdin.file_name = absolute_name_of_file_to_redirect
         _check_contents_of_stdin_for_setup_settings(self,
                                                     setup_settings,
                                                     'contents of file to redirect')
コード例 #19
0
 def test_storage_of_result_in_files__non_existing_dir(self):
     with tmp_dir(DirContents([
         File('program.py',
              program_that_prints_and_exits_with_exit_code(PROCESS_OUTPUT_WITH_NON_ZERO_EXIT_STATUS))
     ])) as tmp_dir_path:
         executor = sut.ExecutorThatStoresResultInFilesInDir(with_no_timeout())
         result = executor.execute(tmp_dir_path / 'non-existing-path-component' / 'one-more-component',
                                   py_exe.args_for_interpreting3(tmp_dir_path / 'program.py'))
         assert_is_success_and_output_dir_contains_at_least_result_files(self,
                                                                         PROCESS_OUTPUT_WITH_NON_ZERO_EXIT_STATUS,
                                                                         result)
コード例 #20
0
 def test_PfhHardError_SHOULD_be_raised_WHEN_file_does_exist_but_is_not_a_regular_file(self):
     # ARRANGE #
     assertion_part = sut.IsExistingRegularFileAssertionPart()
     # ACT & ASSERT #
     with tmp_dir() as path_of_existing_directory:
         with self.assertRaises(PfhHardErrorException):
             assertion_part.check(self.environment, self.the_os_services,
                                  sut.ComparisonActualFile(
                                      described_path.new_primitive(path_of_existing_directory),
                                      True,
                                  )
                                  )
コード例 #21
0
 def test_non_existing_root_dir_SHOULD_not_be_created_when_object_is_constructed(
         self):
     # ARRANGE #
     with tmp_dir() as existing_dir_path:
         space_root_dir = existing_dir_path / 'non-existing-root'
         # ACT #
         sut.DirFileSpaceAsDirCreatedOnDemand(
             space_root_dir,
             FileNamesConfig('-', iter([]), iter([])),
         )
         # ASSERT #
         self.assertFalse(space_root_dir.exists())
コード例 #22
0
 def test_existing_root_dir_SHOULD_not_be_created_when_file_is_demanded(
         self):
     # ARRANGE #
     with tmp_dir() as existing_dir_path:
         space_root_dir = existing_dir_path
         # ACT
         space = sut.DirFileSpaceAsDirCreatedOnDemand(
             space_root_dir,
             FileNamesConfig('-', iter(['name']), iter([])),
         )
         space.new_path()
         # ASSERT #
         self.assertTrue(space_root_dir.is_dir())
コード例 #23
0
 def test_PfhHardError_SHOULD_be_raised_WHEN_file_does_exist_but_is_not_a_regular_file(self):
     # ARRANGE #
     assertion_part = sut.IsExistingRegularFileAssertionPart()
     # ACT & ASSERT #
     with tmp_dir() as path_of_existing_directory:
         with self.assertRaises(PfhHardErrorException):
             assertion_part.check(self.environment, self.the_os_services,
                                  'custom environment',
                                  sut.ComparisonActualFile(
                                      path_of_existing_directory,
                                      file_refs.absolute_file_name(str(path_of_existing_directory)),
                                      FilePropertyDescriptorConstructorTestImpl(),
                                  )
                                  )
コード例 #24
0
 def test_storage_of_result_in_files__existing_dir(self):
     # ARRANGE #
     py_pgm_file = File(
         'program.py',
         program_that_prints_and_exits_with_exit_code(PROCESS_OUTPUT_WITH_NON_ZERO_EXIT_STATUS),
     )
     with tmp_dir.tmp_dir(DirContents([py_pgm_file])) as pgm_dir_path:
         with tmp_dir.tmp_dir() as output_dir_path:
             executor = sut.ProcessorThatStoresResultInFilesInDir(COMMAND_EXECUTOR,
                                                                  output_dir_path,
                                                                  file_ctx_managers.dev_null(),
                                                                  )
             # ACT #
             result = executor.process(ProcessExecutionSettings.null(),
                                       py_exe.command_for_interpreting(pgm_dir_path / py_pgm_file.name)
                                       )
             # ASSERT #
             assert_is_success_and_output_dir_contains_at_exactly_result_files(
                 self,
                 output_dir_path,
                 PROCESS_OUTPUT_WITH_NON_ZERO_EXIT_STATUS,
                 result,
             )
コード例 #25
0
    def test_sub_dir_space(self):
        # ARRANGE #
        for case in _root_dir_cases():
            with self.subTest(case.name):
                with tmp_dir() as existing_dir_path:
                    space_root_dir = case.value(existing_dir_path)
                    root_space = sut.DirFileSpaceAsDirCreatedOnDemand(
                        space_root_dir,
                        FileNamesConfig('-', iter(['a', 'b']),
                                        iter([iter(['1', '2'])])),
                    )
                    # AC & ASSERT #

                    sub_dir_space = root_space.sub_dir_space()

                    self.assertTrue(
                        space_root_dir.is_dir(),
                        'Root space dir should be created when sub space is created'
                    )

                    actual_sub_space_path_1 = sub_dir_space.new_path()

                    expected_sub_space_root_dir = space_root_dir / 'a'
                    expected_sub_space_file_1 = expected_sub_space_root_dir / '1'

                    self.assertTrue(expected_sub_space_root_dir.is_dir())
                    self._assert_num_files_in_dir(
                        expected_sub_space_root_dir,
                        expected_number_of_files=0,
                        msg='Sub dir root dir should be empty')

                    self.assertEqual(actual_sub_space_path_1,
                                     expected_sub_space_file_1)

                    root_file_2 = root_space.new_path()
                    actual_sub_space_path_2 = sub_dir_space.new_path_as_existing_dir(
                    )

                    self._assert_is_non_existing_file(space_root_dir / 'b',
                                                      root_file_2)
                    self._assert_is_existing_dir(
                        expected_sub_space_root_dir / '2',
                        actual_sub_space_path_2)
                    self._assert_num_files_in_dir(space_root_dir,
                                                  expected_number_of_files=1)
                    self._assert_num_files_in_dir(expected_sub_space_root_dir,
                                                  expected_number_of_files=1)
コード例 #26
0
ファイル: common.py プロジェクト: emilkarlen/exactly
    def test_unique_instruction_file_as_existing_dir(self):
        # ARRANGE #
        with tmp_dir() as root_dir:
            phase_identifier = 'phase-identifier'
            logger = sut.PhaseLoggingPaths(root_dir, phase_identifier)

            expected_phase_root_dir = sandbox_directory_structure.log_phase_dir(root_dir, phase_identifier)
            expected_base_name = sut.PhaseLoggingPaths.instruction_file_format.format(1)
            expected_path = expected_phase_root_dir / expected_base_name

            # ACT #
            instruction_dir = logger.unique_instruction_file_as_existing_dir()
            # ASSERT #
            self.assertEqual(expected_path,
                             instruction_dir)
            self.assertTrue(instruction_dir.is_dir(),
                            'the instruction directory should exist and be a directory')
コード例 #27
0
    def test_exit_code(self):
        exit_code = 3
        py_pgm_that_exits_with_exit_code = """
import sys
sys.exit(%d)
""" % exit_code

        with tmp_dir(DirContents([
            File('program.py', py_pgm_that_exits_with_exit_code)
        ])) as tmp_dir_path:
            executor = sut.ExecutorThatStoresResultInFilesInDir(with_no_timeout())
            result = executor.execute(tmp_dir_path,
                                      py_exe.args_for_interpreting3(tmp_dir_path / 'program.py'))
            self.assertTrue(result.is_success,
                            'Result should indicate success')
            self.assertEqual(exit_code,
                             result.exit_code,
                             'Exit code')
コード例 #28
0
    def test_sub_dir_spaces_SHOULD_use_names_from_consecutive_name_iterators__w_name_suffixes(
            self):
        # ARRANGE #
        for case in _root_dir_cases():
            with self.subTest(case.name):
                with tmp_dir() as existing_dir_path:
                    space_root_dir = case.value(existing_dir_path)
                    root_space = sut.DirFileSpaceAsDirCreatedOnDemand(
                        space_root_dir,
                        FileNamesConfig(
                            '--', iter(['a', 'b']),
                            iter([
                                iter(['1', '2']),
                                iter(['10', '20']),
                            ])),
                    )
                    # AC & ASSERT #

                    sub_dir_space_1 = root_space.sub_dir_space('A')
                    sub_dir_space_2 = root_space.sub_dir_space('B')

                    path_1_1 = sub_dir_space_1.new_path('1_1')
                    path_1_2 = sub_dir_space_1.new_path('1_2')

                    path_2_1 = sub_dir_space_2.new_path('2_1')
                    path_2_2 = sub_dir_space_2.new_path('2_2')

                    self.assertEqual(
                        space_root_dir / 'a--A' / '1--1_1',
                        path_1_1,
                    )
                    self.assertEqual(
                        space_root_dir / 'a--A' / '2--1_2',
                        path_1_2,
                    )

                    self.assertEqual(
                        space_root_dir / 'b--B' / '10--2_1',
                        path_2_1,
                    )
                    self.assertEqual(
                        space_root_dir / 'b--B' / '20--2_2',
                        path_2_2,
                    )
コード例 #29
0
    def execute(self,
                parser: Parser[ProgramResolver],
                source: ParseSource):
        program_resolver = parser.parse(source)
        self.expectation.source.apply_with_message(self.put, source, 'source')
        assert isinstance(program_resolver, ProgramResolver)
        self.expectation.symbol_references.apply_with_message(self.put,
                                                              program_resolver.references,
                                                              'symbol-usages after parse')
        with home_and_sds_with_act_as_curr_dir(
                pre_contents_population_action=self.arrangement.pre_contents_population_action,
                hds_contents=self.arrangement.hds_contents,
                sds_contents=self.arrangement.sds_contents,
                non_home_contents=self.arrangement.non_home_contents,
                home_or_sds_contents=self.arrangement.home_or_sds_contents,
                symbols=self.arrangement.symbols) as path_resolving_environment:
            self.arrangement.post_sds_population_action.apply(path_resolving_environment)

            with tmp_dir.tmp_dir() as pgm_output_dir:
                self.check(pgm_output_dir, path_resolving_environment, program_resolver)
コード例 #30
0
    def _setup(
        self,
        contents_dir_contents: DirContents,
        source: str,
    ):
        # ARRANGE #
        parse_source = remaining_source(source)
        # ACT #
        actual_parse_result = self._parser().parse(ARBITRARY_FS_LOCATION_INFO,
                                                   parse_source)
        # ASSERT preconditions #

        self.assertIsInstance(actual_parse_result,
                              parsed_section_element.ParsedInstruction)
        instruction = actual_parse_result.instruction_info.instruction
        self.assertIsInstance(instruction, self._expected_instruction_class())
        assert isinstance(instruction, TestSuiteFileReferencesInstruction)

        with tmp_dir(contents_dir_contents) as contents_dir:
            yield instruction, contents_dir
コード例 #31
0
    def test_invalid_executable_SHOULD_raise_hard_error(self):
        # ARRANGE #
        with tmp_dir.tmp_dir() as tmp_dir_path:
            with self.assertRaises(HardErrorException) as ctx:
                executor = sut.ProcessorThatStoresResultInFilesInDir(COMMAND_EXECUTOR,
                                                                     tmp_dir_path,
                                                                     file_ctx_managers.dev_null(),
                                                                     )

                # ACT & ASSERT #
                executor.process(
                    ProcessExecutionSettings.null(),
                    command_for_exe_file(tmp_dir_path / 'non-existing-program'),
                )
        assert isinstance(ctx.exception, HardErrorException)
        asrt_text_doc.is_any_text().apply_with_message(
            self,
            ctx.exception.error,
            'exception error message'
        )
コード例 #32
0
    def _setup(self,
               contents_dir_contents: DirContents,
               source: str,
               ):
        # ARRANGE #
        parse_source = remaining_source(source)
        # ACT #
        actual_parse_result = self._parser().parse(ARBITRARY_FS_LOCATION_INFO,
                                                   parse_source)
        # ASSERT preconditions #

        self.assertIsInstance(actual_parse_result,
                              parsed_section_element.ParsedInstruction)
        instruction = actual_parse_result.instruction_info.instruction
        self.assertIsInstance(instruction,
                              self._expected_instruction_class())
        assert isinstance(instruction, TestSuiteFileReferencesInstruction)

        with tmp_dir(contents_dir_contents) as contents_dir:
            yield instruction, contents_dir
コード例 #33
0
    def test_exit_code(self):
        # ARRANGE #
        exit_code = 3

        program_file = File(
            'program.py',
            py_programs.py_pgm_with_stdout_stderr_exit_code(exit_code=exit_code),
        )
        with tmp_dir.tmp_dir(DirContents([program_file])) as tmp_dir_path:
            executor = sut.ProcessorThatStoresResultInFilesInDir(COMMAND_EXECUTOR,
                                                                 tmp_dir_path,
                                                                 file_ctx_managers.dev_null(),
                                                                 )
            # ACT #
            result = executor.process(ProcessExecutionSettings.null(),
                                      py_exe.command_for_interpreting(tmp_dir_path / program_file.name))
            # ASSERT #
            self.assertEqual(exit_code,
                             result.exit_code,
                             'Exit code')
コード例 #34
0
    def test_model_is_returned_WHEN_file_is_existing_regular_file(self):
        # ARRANGE #

        assertion_part = sut.IsExistingRegularFileAssertionPart()

        existing_regular_file = File.empty('regular.txt')

        with tmp_dir(DirContents([existing_regular_file])) as path_of_existing_directory:
            path_of_existing_regular_file = path_of_existing_directory / existing_regular_file.name
            path_ddv = path_ddvs.absolute_path(path_of_existing_regular_file)
            path = path_ddv.value_of_any_dependency__d(fake_tcds())
            model = sut.ComparisonActualFile(path,
                                             True)
            # ACT #

            actual = assertion_part.check(self.environment, self.the_os_services,
                                          model)
            # ASSERT #

            self.assertIs(model, actual)
コード例 #35
0
    def test_model_is_returned_WHEN_file_is_existing_regular_file(self):
        # ARRANGE #

        assertion_part = sut.IsExistingRegularFileAssertionPart()

        existing_regular_file = empty_file('regular.txt')

        with tmp_dir(DirContents([existing_regular_file])) as path_of_existing_directory:
            path_of_existing_regular_file = path_of_existing_directory / existing_regular_file.name
            model = sut.ComparisonActualFile(path_of_existing_regular_file,
                                             file_refs.absolute_path(path_of_existing_regular_file),
                                             FilePropertyDescriptorConstructorTestImpl(), )

            # ACT #

            actual = assertion_part.check(self.environment, self.the_os_services,
                                          'custom environment',
                                          model)
            # ASSERT #

            self.assertIs(model, actual)
コード例 #36
0
ファイル: atc_execution.py プロジェクト: emilkarlen/exactly
    def test_WHEN_stdin_is_set_THEN_it_SHOULD_be_passed_to_the_atc(self):
        file_with_stdin_contents = fs.File('redirected-to-stdin.txt',
                                           'contents of file to redirect')
        with tmp_dir(fs.DirContents([file_with_stdin_contents
                                     ])) as abs_tmp_dir_path:
            absolute_name_of_file_to_redirect = abs_tmp_dir_path / file_with_stdin_contents.name

            def mk_setup_settings_handler(
                    environ: OptionalEnvVarsDict) -> SetupSettingsHandler:
                ret_val = StandardSetupSettingsHandler.new_empty()
                builder = ret_val.builder
                builder.environ = environ
                builder.stdin = ConstantAdvWValidation.new_wo_validation(
                    file_source.string_source_of_file__poorly_described(
                        absolute_name_of_file_to_redirect,
                        DirFileSpaceThatMustNoBeUsed()))
                return ret_val

            _check_contents_of_stdin_for_setup_settings(
                self, mk_setup_settings_handler,
                file_with_stdin_contents.contents)
コード例 #37
0
ファイル: path_type.py プロジェクト: emilkarlen/exactly
 def test(self):
     with tmp_dir() as abs_path_of_dir_containing_last_file_base_name:
         fs_location_info = FileSystemLocationInfo(
             FileLocationInfo(abs_path_of_dir_containing_last_file_base_name))
         instruction_argument = src('{path_type} name = {rel_source_file} component')
         for source in equivalent_source_variants__with_source_check(self, instruction_argument):
             expected_file_ref_resolver = file_ref_resolvers.constant(
                 file_refs.rel_abs_path(abs_path_of_dir_containing_last_file_base_name,
                                        file_refs.constant_path_part('component')))
             expected_container = resolver_container(expected_file_ref_resolver)
             self._check(source,
                         ArrangementWithSds(fs_location_info=fs_location_info),
                         Expectation(
                             symbol_usages=assert_symbol_usages_is_singleton_list(
                                 vs_asrt.equals_symbol(
                                     SymbolDefinition('name', expected_container))),
                             symbols_after_main=assert_symbol_table_is_singleton(
                                 'name',
                                 equals_container(expected_container))
                         )
                         )
コード例 #38
0
 def test_demanded_files_in_root_dir_SHOULD_be_that_of_iterator__non_existing_root_dir(
         self):
     # ARRANGE #
     for case in _root_dir_cases():
         with self.subTest(case.name):
             with tmp_dir() as existing_dir_path:
                 space_root_dir = case.value(existing_dir_path)
                 # ACT
                 space = sut.DirFileSpaceAsDirCreatedOnDemand(
                     space_root_dir,
                     FileNamesConfig('-', iter(['a', 'b']), iter([])),
                 )
                 file_1 = space.new_path()
                 file_2 = space.new_path()
                 # ASSERT #
                 self._assert_is_non_existing_file(space_root_dir / 'a',
                                                   file_1)
                 self._assert_is_non_existing_file(space_root_dir / 'b',
                                                   file_2)
                 self._assert_num_files_in_dir(space_root_dir,
                                               expected_number_of_files=0)
コード例 #39
0
 def test_phase(self):
     # ARRANGE #
     with tmp_dir.tmp_dir() as root_dir:
         factory = sut.PhaseTmpFileSpaceFactory(root_dir)
         cases = [
             NameAndValue(
                 phase_identifier.ASSERT.identifier,
                 phase_identifier.ASSERT,
             ),
             NameAndValue(
                 phase_identifier.ACT.identifier,
                 phase_identifier.ACT,
             ),
         ]
         for case in cases:
             with self.subTest(case.name):
                 expected_dir = root_dir / _expected_phase_dir(case.value)
                 # ACT & ASSERT #
                 _check(
                     self,
                     expected_dir,
                     factory.for_phase__main(case.value),
                 )
コード例 #40
0
    def execute(self,
                parser: InstructionParser,
                source: ParseSource):
        with tmp_dir(self.arrangement.root_dir_contents) as abs_path_of_dir_containing_root_file:
            fs_location_info = FileSystemLocationInfo(FileLocationInfo(
                abs_path_of_dir_containing_root_file))

            instruction = parser.parse(fs_location_info, source)

            self.put.assertIsNotNone(instruction,
                                     'Result from parser cannot be None')
            self.put.assertIsInstance(instruction,
                                      ConfigurationPhaseInstruction,
                                      'The instruction must be an instance of ' + str(ConfigurationPhaseInstruction))
            self.expectation.source.apply_with_message(self.put, source, 'source')

            assert isinstance(instruction, ConfigurationPhaseInstruction)

            with home_directory_structure(contents=self.arrangement.hds_contents) as hds:
                configuration_builder = ConfigurationBuilder(hds.case_dir,
                                                             hds.act_dir,
                                                             self.arrangement.actor,
                                                             timeout_in_seconds=self.arrangement.timeout_in_seconds,
                                                             test_case_status=self.arrangement.test_case_status)

                self._execute_main(configuration_builder, instruction)

                self.expectation.configuration.apply_with_message(self.put,
                                                                  configuration_builder,
                                                                  'ConfigurationBuilder')

                self.expectation.file_ref_rel_root_2_conf(
                    abs_path_of_dir_containing_root_file
                ).apply_with_message(self.put,
                                     configuration_builder,
                                     'ConfigurationBuilder with file-ref-rel-root-dir')
コード例 #41
0
    def test_fail_WHEN_storage_dir_is_an_existing_regular_file(self):
        # ARRANGE #
        successful_py_program = File(
            'successful.py',
            py_programs.py_pgm_with_stdout_stderr_exit_code(exit_code=0),
        )
        existing_file = File.empty('a-file')
        dir_contents = DirContents([successful_py_program, existing_file])

        with tmp_dir.tmp_dir(dir_contents) as tmp_dir_path:
            path_of_existing_regular_file = tmp_dir_path / existing_file.name
            executor = sut.ProcessorThatStoresResultInFilesInDir(
                COMMAND_EXECUTOR,
                path_of_existing_regular_file,
                file_ctx_managers.dev_null(),
            )
            with self.assertRaises(exception.ImplementationError) as ctx:
                # ACT & ASSERT #
                executor.process(
                    ProcessExecutionSettings.null(),
                    command_for_exe_file(tmp_dir_path / successful_py_program.name),
                )
        assert isinstance(ctx.exception, exception.ImplementationError)
        self.assertIsInstance(ctx.exception.message, str, 'exception info')
コード例 #42
0
ファイル: file_type.py プロジェクト: emilkarlen/exactly
    def _check(self,
               file_type_to_check_for: FileType,
               expected_result: bool,
               base_name_of_file_to_check: str,
               dir_contents: DirContents):
        matcher_to_check = sut.FileMatcherType(file_type_to_check_for)
        self.assertIsInstance(matcher_to_check.option_description,
                              str,
                              'option_description')
        # ACT #
        with tmp_dir(dir_contents) as tmp_dir_path:
            file_path_to_check = tmp_dir_path / base_name_of_file_to_check

            actual_result = matcher_to_check.matches(model.with_dir_space_that_must_not_be_used(file_path_to_check))

            # ASSERT #

            self.assertEqual(file_type_to_check_for,
                             matcher_to_check.file_type,
                             'file type')

            self.assertEqual(expected_result,
                             actual_result,
                             'result')
コード例 #43
0
ファイル: file_properties.py プロジェクト: emilkarlen/exactly
def empty_directory() -> pathlib.Path:
    with tmp_dir() as dir_path:
        yield dir_path / 'non-existing-file'
コード例 #44
0
def dir_file_space_with_existing_dir() -> ContextManager[DirFileSpace]:
    with tmp_dir.tmp_dir() as storage_dir:
        yield tmp_file_spaces.tmp_dir_file_space_for_test(storage_dir)
コード例 #45
0
ファイル: file_properties.py プロジェクト: emilkarlen/exactly
def dir_with_symlink_to_existing_dir() -> pathlib.Path:
    with tmp_dir(DirContents([empty_dir('existing-dir'),
                              sym_link('existing-symlink',
                                       'existing-dir')])) as dir_path:
        yield dir_path / 'existing-symlink'
コード例 #46
0
ファイル: file_properties.py プロジェクト: emilkarlen/exactly
def empty_directory() -> pathlib.Path:
    with tmp_dir() as dir_path:
        yield dir_path / 'non-existing-file'