コード例 #1
0
def test_ReadGithubAccessTokenPath_invalid_is_directory(tempdir: pathlib.Path,):
  path = tempdir / "access_token.txt"
  path.mkdir()
  with test.Raises(api.BadCredentials) as e_ctx:
    api.ReadGithubAccessTokenPath(path)

  assert str(e_ctx.value) == "File is a directory"
コード例 #2
0
def test_ReadGithubAccessTokenPath_invalid_empty_file(tempdir: pathlib.Path):
  path = tempdir / "access_token.txt"
  path.touch()
  with test.Raises(api.BadCredentials) as e_ctx:
    api.ReadGithubAccessTokenPath(path)

  assert str(e_ctx.value) == "Access token not found in file"
コード例 #3
0
def test_ReadGithubAccessTokenPath_invalid_no_permissions(
  tempdir: pathlib.Path,
):
  path = tempdir / "access_token.txt"
  path.touch()
  os.chmod(path, 0o000)
  with test.Raises(api.BadCredentials) as e_ctx:
    api.ReadGithubAccessTokenPath(path)

  assert str(e_ctx.value) == "Cannot read file"
コード例 #4
0
def test_ReadGithubAccessTokenPath_valid_file(tempdir: pathlib.Path,):
  path = tempdir / "access_token.txt"
  fs.Write(path, "1234".encode("utf-8"))

  assert api.ReadGithubAccessTokenPath(path) == "1234"
コード例 #5
0
def test_ReadGithubAccessTokenPath_file_not_found(tempdir: pathlib.Path):
  with test.Raises(FileNotFoundError):
    api.ReadGithubAccessTokenPath(tempdir / "not_a_file.txt")
コード例 #6
0
# Copyright 2018-2020 Chris Cummins <*****@*****.**>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This module exposes the path of an access token for testing, the access token
contents, if it exists.
"""
from datasets.github import api

ACCESS_TOKEN_PATH = api.TEST_ACCESS_TOKEN_PATH

if ACCESS_TOKEN_PATH.is_file():
    ACCESS_TOKEN = api.ReadGithubAccessTokenPath(ACCESS_TOKEN_PATH)
else:
    ACCESS_TOKEN = None