Exemple #1
0
def test__check_file_with_correct_tag(mock_get_tag, mock_validate,
                                      mock_get_example):
    tag = ExampleTag({"name": "Name"}, "")
    example = Example(name="filename",
                      sdk=SDK_JAVA,
                      filepath="/root/filename.java",
                      code="data",
                      status=STATUS_UNSPECIFIED,
                      tag=Tag("Name", "Description", False, [],
                              '--option option'))
    examples = []

    mock_get_tag.return_value = tag
    mock_validate.return_value = True
    mock_get_example.return_value = example

    result = _check_file(examples,
                         "filename.java",
                         "/root/filename.java", [],
                         sdk=SDK_JAVA)

    assert result is False
    assert len(examples) == 1
    assert examples[0] == example
    mock_get_tag.assert_called_once_with("/root/filename.java")
    mock_validate.assert_called_once_with(tag.tag_as_dict, [])
    mock_get_example.assert_called_once_with("/root/filename.java",
                                             "filename.java", tag)
Exemple #2
0
def test__check_file_with_incorrect_tag(mock_get_tag, mock_validate):
    tag = ExampleTag({"name": "Name"}, "")
    examples = []
    sdk = SDK_JAVA
    mock_get_tag.return_value = tag
    mock_validate.return_value = False

    result = _check_file(examples, "filename.java", "/root/filename.java", [],
                         sdk)

    assert result is True
    assert len(examples) == 0
    mock_get_tag.assert_called_once_with("/root/filename.java")
    mock_validate.assert_called_once_with(tag.tag_as_dict, [])
Exemple #3
0
def test__get_example(mock_get_name):
    mock_get_name.return_value = "filepath"
    tag = ExampleTag(
        {
            "name": "Name",
            "description": "Description",
            "multifile": "False",
            "categories": [""],
            "pipeline_options": "--option option"
        }, "")

    result = _get_example("/root/filepath.java", "filepath.java", tag)

    assert result == Example(name="filepath",
                             sdk=SDK_JAVA,
                             filepath="/root/filepath.java",
                             code="data",
                             status=STATUS_UNSPECIFIED,
                             tag=Tag("Name", "Description", "False", [""],
                                     "--option option"))
    mock_get_name.assert_called_once_with("filepath.java")
Exemple #4
0
def test__get_example(mock_get_name):
  mock_get_name.return_value = "filepath"
  tag = ExampleTag({
      "name": "Name",
      "description": "Description",
      "multifile": "False",
      "categories": [""],
      "pipeline_options": "--option option",
      "context_line": 1
  },
                   "")

  result = _get_example("/root/filepath.java", "filepath.java", tag)

  assert result == Example(
      name="filepath",
      sdk=SDK_JAVA,
      filepath="/root/filepath.java",
      code="data",
      status=STATUS_UNSPECIFIED,
      tag=Tag(
          "Name", "Description", "False", [""], "--option option", False, 1),
      link="https://github.com/apache/beam/blob/master/root/filepath.java")
  mock_get_name.assert_called_once_with("filepath.java")