Skip to content
Permalink
Browse files

Added _SkipIfPathNotExists in test_lib (#335)

  • Loading branch information...
joachimmetz committed May 4, 2019
1 parent 6400e78 commit ba4c8034e764e1bd0c38d550ccf1d2f66123f9e0
Showing with 19 additions and 14 deletions.
  1. +4 −9 tests/reader_test.py
  2. +1 −3 tests/registry_test.py
  3. +13 −0 tests/test_lib.py
  4. +1 −2 tests/writer_test.py
@@ -4,7 +4,6 @@
from __future__ import unicode_literals

import io
import os
import unittest
import yaml

@@ -117,8 +116,7 @@ class YamlArtifactsReaderTest(test_lib.BaseTestCase):
def testReadFileObject(self):
"""Tests the ReadFileObject function."""
test_file = self._GetTestFilePath(['definitions.yaml'])
if not os.path.exists(test_file):
raise unittest.SkipTest('missing test file: definitions.yaml')
self._SkipIfPathNotExists(test_file)

artifact_reader = reader.YamlArtifactsReader()

@@ -321,8 +319,7 @@ def testReadFileObjectWithoutSources(self):
def testReadYamlFile(self):
"""Tests the ReadFile function."""
test_file = self._GetTestFilePath(['definitions.yaml'])
if not os.path.exists(test_file):
raise unittest.SkipTest('missing test file: definitions.yaml')
self._SkipIfPathNotExists(test_file)

artifact_reader = reader.YamlArtifactsReader()

@@ -340,8 +337,7 @@ def testReadDirectory(self):
def testArtifactAsDict(self):
"""Tests the AsDict function."""
test_file = self._GetTestFilePath(['definitions.yaml'])
if not os.path.exists(test_file):
raise unittest.SkipTest('missing test file: definitions.yaml')
self._SkipIfPathNotExists(test_file)

artifact_reader = reader.YamlArtifactsReader()

@@ -375,8 +371,7 @@ class JsonArtifactsReaderTest(test_lib.BaseTestCase):
def testReadJsonFile(self):
"""Tests the ReadFile function."""
test_file = self._GetTestFilePath(['definitions.json'])
if not os.path.exists(test_file):
raise unittest.SkipTest('missing test file: definitions.json')
self._SkipIfPathNotExists(test_file)

artifact_reader = reader.JsonArtifactsReader()

@@ -4,7 +4,6 @@
from __future__ import unicode_literals

import io
import os
import unittest

from artifacts import errors
@@ -52,8 +51,7 @@ class ArtifactDefinitionsRegistryTest(test_lib.BaseTestCase):
def testArtifactDefinitionsRegistry(self):
"""Tests the ArtifactDefinitionsRegistry functions."""
test_file = self._GetTestFilePath(['definitions.yaml'])
if not os.path.exists(test_file):
raise unittest.SkipTest('missing test file: definitions.yaml')
self._SkipIfPathNotExists(test_file)

artifact_registry = registry.ArtifactDefinitionsRegistry()

@@ -32,6 +32,19 @@ def _GetTestFilePath(self, path_segments):
# and not a list.
return os.path.join(self._TEST_DATA_PATH, *path_segments)

def _SkipIfPathNotExists(self, path):
"""Skips the test if the path does not exist.
Args:
path (str): path of a test file.
Raises:
SkipTest: if the path path does not exist and the test should be skipped.
"""
if not os.path.exists(path):
filename = os.path.basename(path)
raise unittest.SkipTest('missing test file: {0:s}'.format(filename))


class TempDirectory(object):
"""Class that implements a temporary directory."""
@@ -25,8 +25,7 @@ def _TestArtifactsConversion(
filename (str): name of the file to convert.
"""
test_file = self._GetTestFilePath([filename])
if not os.path.exists(test_file):
raise unittest.SkipTest('missing test file: {0:s}'.format(filename))
self._SkipIfPathNotExists(test_file)

artifact_definitions = list(artifact_reader.ReadFile(test_file))

0 comments on commit ba4c803

Please sign in to comment.
You can’t perform that action at this time.