Esempio n. 1
0
 def test_equals(self):
     path = pathlib.Path('here')
     cases = [
         NEA(
             'without arguments',
             expected=CommandDriverForExecutableFile(new_primitive(path)),
             actual=CommandDriverForExecutableFile(new_primitive(path)),
         ),
     ]
     for case in cases:
         assertion = sut.equals_executable_file_command_driver(
             case.expected)
         with self.subTest(case.name):
             assertion.apply_without_message(self, case.actual)
Esempio n. 2
0
 def test_equals(self):
     cases = [
         NEA(
             '',
             expected=sut.equals_executable_file_command(
                 new_primitive(pathlib.Path('expected')), ['arg']),
             actual=Command(
                 CommandDriverForExecutableFile(
                     new_primitive(pathlib.Path('expected'))), ['arg']),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             case.expected.apply_without_message(self, case.actual)
Esempio n. 3
0
    def test_executable_file(self):
        # ARRANGE #
        the_file = pathlib.Path('the dir') / 'the file'
        cases = [
            NIE('without arguments',
                expected_value=[str(the_file)],
                input_value=[],
                ),
            NIE('with arguments',
                expected_value=[str(the_file), 'arg1', 'arg2'],
                input_value=['arg1', 'arg2'],
                ),
        ]
        for case in cases:
            with self.subTest(case.name):
                command = Command(CommandDriverForExecutableFile(new_primitive(the_file)),
                                  case.input_value)
                # ACT #
                actual = self.factory.make(command)
                # ASSERT #
                self.assertFalse(actual.is_shell)

                self.assertIsInstance(actual.arg_list_or_str, list)

                self.assertEqual(case.expected_value, actual.arg_list_or_str)
Esempio n. 4
0
 def test_no_exception_SHOULD_be_not_raised_WHEN_file_does_not_exist_but_file_does_not_need_to_be_verified(self):
     # ARRANGE #
     assertion_part = sut.IsExistingRegularFileAssertionPart()
     # ACT & ASSERT #
     path = pathlib.Path('a file that does not exist')
     assertion_part.check(self.environment, self.the_os_services,
                          sut.ComparisonActualFile(
                              described_path.new_primitive(path),
                              False,
                          ))
Esempio n. 5
0
 def test_not_equals(self):
     cases = [
         NEA(
             'unexpected file',
             expected=sut.equals_executable_file_command(
                 new_primitive(pathlib.Path('expected')), []),
             actual=Command(
                 CommandDriverForExecutableFile(
                     new_primitive(pathlib.Path('unExpected'))), []),
         ),
         NEA(
             'unexpected driver type',
             expected=sut.equals_executable_file_command(
                 new_primitive(pathlib.Path('expected')), []),
             actual=Command(CommandDriverForSystemProgram('expected'), []),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             assert_that_assertion_fails(case.expected, case.actual)
Esempio n. 6
0
 def test_not_equals(self):
     path = pathlib.Path('here')
     cases = [
         NEA(
             'unexpected path',
             expected=CommandDriverForExecutableFile(new_primitive(path)),
             actual=CommandDriverForExecutableFile(
                 new_primitive(path / 'unexpected')),
         ),
         NEA(
             'unexpected command type',
             expected=CommandDriverForExecutableFile(new_primitive(path)),
             actual=CommandDriverForSystemProgram(path.name),
         ),
     ]
     for case in cases:
         assertion = sut.equals_executable_file_command_driver(
             case.expected)
         with self.subTest(case.name):
             assert_that_assertion_fails(assertion, case.actual)
Esempio n. 7
0
 def test_PfhHardError_SHOULD_be_raised_WHEN_file_does_not_exist(self):
     # ARRANGE #
     assertion_part = sut.IsExistingRegularFileAssertionPart()
     # ACT & ASSERT #
     with self.assertRaises(PfhHardErrorException):
         path = pathlib.Path('a file that does not exist')
         assertion_part.check(self.environment, self.the_os_services,
                              sut.ComparisonActualFile(
                                  described_path.new_primitive(path),
                                  True,
                              ))
Esempio n. 8
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,
                                  )
                                  )
def _to_upper_command(empty_tmp_dir: Path, exit_code: int) -> Command:
    py_program = fs.File(
        'to-upper.py',
        _to_upper_stdin_py_program_w_exit_code(exit_code))
    fs.DirContents([py_program]).write_to(empty_tmp_dir)

    return Command(
        CommandDriverForExecutableFile(
            described_path.new_primitive(Path(sys.executable))
        ),
        [str(empty_tmp_dir / py_program.name)]
    )
Esempio n. 10
0
 def test_visit_executable_file(self):
     # ARRANGE #
     visitor = _CommandDriverArgumentTypePseudoVisitorThatRegistersClassOfVisitedObjects(
         'return value')
     # ACT #
     ret_val = visitor.visit(
         sut.CommandDriverForExecutableFile(
             described_path.new_primitive(pathlib.Path.cwd())))
     # ASSERT #
     self.assertEqual(
         'return value', ret_val,
         'Visitor is expected to return value from visit-method')
     self.assertListEqual(visitor.visited_classes,
                          [sut.CommandDriverWithArgumentList],
                          'visited classes')
Esempio n. 11
0
    def apply(self,
              put: unittest.TestCase,
              message_builder: MessageBuilder,
              primitive: FilesSource,
              resolving_environment: FullResolvingEnvironment,
              input_: FileSystemElements) -> pathlib.Path:
        dir_arrangement = fs.DirContents([
            fs.Dir(self.NON_SDS_ROOT_FILE_NAME,
                   list(input_))
        ])

        existing_dir = resolving_environment.tcds.sds.root_dir

        dir_arrangement.write_to(existing_dir)

        population_dir = existing_dir / self.NON_SDS_ROOT_FILE_NAME

        primitive.populate(described_path.new_primitive(population_dir))

        return population_dir
Esempio n. 12
0
def command_that_runs_py_file(
    py_src_file: Path, arguments_after_py_file: Sequence[str] = ()) -> Command:
    return Command(
        CommandDriverForExecutableFile(
            described_path.new_primitive(Path(sys.executable))),
        [str(py_src_file)] + list(arguments_after_py_file))
Esempio n. 13
0
def new_model(path: pathlib.Path) -> FileMatcherModel:
    return FileMatcherModelForDescribedPath(described_path.new_primitive(path))
Esempio n. 14
0
def command_that_runs_py_src_via_cmd_line(py_src: str) -> Command:
    return Command(
        CommandDriverForExecutableFile(
            described_path.new_primitive(Path(sys.executable))),
        [PY_ARG_FOR_EXECUTING_SOURCE_ON_COMMAND_LINE,
         str(py_src)])
Esempio n. 15
0
def command_that_runs_executable_file(
    exe_file: Path, arguments: Sequence[str] = ()) -> Command:
    return Command(
        CommandDriverForExecutableFile(described_path.new_primitive(exe_file)),
        list(arguments))
Esempio n. 16
0
 def __init__(self, action_dir_path: pathlib.Path):
     self.action_dir_path = described_path.new_primitive(action_dir_path)
Esempio n. 17
0
 def ret_val(environment: FullResolvingEnvironment) -> DescribedPath:
     return described_path.new_primitive(pathlib.Path(file_name))
Esempio n. 18
0
def command_for_interpreting(python_source_file_path_or_name,
                             arguments: Sequence[str] = ()) -> Command:
    return Command(
        CommandDriverForExecutableFile(described_path.new_primitive(pathlib.Path(sys.executable))),
        [str(python_source_file_path_or_name)] + _str_elements(arguments)
    )
Esempio n. 19
0
def command_for_exe_file(exe_file: pathlib.Path) -> Command:
    return Command(
        CommandDriverForExecutableFile(described_path.new_primitive(exe_file)),
        [],
    )
Esempio n. 20
0
    def test_successful_parse(self):
        name_pattern = 'the name pattern'
        non_matching_name = 'non-matching name'

        glob_pattern_arguments = file_matcher_arguments(
            name_pattern=name_pattern)
        sut_parser = parse_file_matcher.parsers().full
        expected_glob_pattern_matcher_sdv = sut_parser.parse(
            remaining_source(glob_pattern_arguments))

        expected_glob_pattern_matcher = resolving_helper__fake(
        ).resolve_matcher(expected_glob_pattern_matcher_sdv)

        cases = [
            NIE(
                'name pattern in RHS SHOULD give selection of name pattern',
                asrt_matcher.is_equivalent_to(expected_glob_pattern_matcher, [
                    asrt_matcher.ModelInfo(
                        file_matcher_models.FileMatcherModelForDescribedPath(
                            described_path.new_primitive(
                                pathlib.Path(name_pattern)), )),
                    asrt_matcher.ModelInfo(
                        file_matcher_models.FileMatcherModelForDescribedPath(
                            described_path.new_primitive(
                                pathlib.Path(non_matching_name)), )),
                ]),
                glob_pattern_arguments,
            ),
        ]
        # ARRANGE #
        defined_name = 'defined_name'
        argument_cases = [
            NameAndValue('value on same line', '{selector_argument}'),
            NameAndValue('value on following line',
                         '{new_line} {selector_argument}'),
        ]

        for case in cases:
            for argument_case in argument_cases:
                with self.subTest(case.name, arguments=argument_case.name):
                    source = single_line_source(
                        src2(ValueType.FILE_MATCHER,
                             defined_name,
                             argument_case.value,
                             selector_argument=case.input_value), )

                    expected_container = matches_container(
                        asrt.equals(ValueType.FILE_MATCHER),
                        type_sdv_assertions.matches_sdv_of_file_matcher(
                            references=asrt.is_empty_sequence,
                            primitive_value=case.expected_value))

                    expectation = Expectation.phase_agnostic(
                        symbol_usages=asrt.matches_sequence([
                            asrt_sym_usage.matches_definition(
                                asrt.equals(defined_name), expected_container)
                        ]),
                        symbols_after_main=assert_symbol_table_is_singleton(
                            defined_name,
                            expected_container,
                        ))
                    # ACT & ASSERT #
                    INSTRUCTION_CHECKER.check(self, source,
                                              Arrangement.phase_agnostic(),
                                              expectation)
Esempio n. 21
0
def equals_execute_py_source_command(source: str) -> Assertion[Command]:
    return equals_executable_file_command(
        new_primitive(pathlib.Path(sys.executable)), [
            python_program_execution.
            PY_ARG_FOR_EXECUTING_SOURCE_ON_COMMAND_LINE, source
        ])