From 3324490e0669ba15a8b1d54051ff4b387e28b27a Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Fri, 11 Jan 2019 15:56:33 -0500 Subject: tests: Migrate context test into the internals directory --- tests/context/__init__.py | 0 tests/context/context.py | 132 --------------------------------- tests/context/data/malformed.yaml | 4 - tests/context/data/notdict.yaml | 1 - tests/context/data/userconf.yaml | 3 - tests/internals/context.py | 132 +++++++++++++++++++++++++++++++++ tests/internals/context/malformed.yaml | 4 + tests/internals/context/notdict.yaml | 1 + tests/internals/context/userconf.yaml | 3 + 9 files changed, 140 insertions(+), 140 deletions(-) delete mode 100644 tests/context/__init__.py delete mode 100644 tests/context/context.py delete mode 100644 tests/context/data/malformed.yaml delete mode 100644 tests/context/data/notdict.yaml delete mode 100644 tests/context/data/userconf.yaml create mode 100644 tests/internals/context.py create mode 100644 tests/internals/context/malformed.yaml create mode 100644 tests/internals/context/notdict.yaml create mode 100644 tests/internals/context/userconf.yaml diff --git a/tests/context/__init__.py b/tests/context/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/context/context.py b/tests/context/context.py deleted file mode 100644 index 35428105b..000000000 --- a/tests/context/context.py +++ /dev/null @@ -1,132 +0,0 @@ -import os -import pytest - -from buildstream._context import Context -from buildstream._exceptions import LoadError, LoadErrorReason - -DATA_DIR = os.path.join( - os.path.dirname(os.path.realpath(__file__)), - 'data', -) - - -# Simple fixture to create a Context object. -@pytest.fixture() -def context_fixture(): - if os.environ.get('XDG_CACHE_HOME'): - cache_home = os.environ['XDG_CACHE_HOME'] - else: - cache_home = os.path.expanduser('~/.cache') - - return { - 'xdg-cache': cache_home, - 'context': Context() - } - - -####################################### -# Test instantiation # -####################################### -def test_context_create(context_fixture): - context = context_fixture['context'] - assert(isinstance(context, Context)) - - -####################################### -# Test configuration loading # -####################################### -def test_context_load(context_fixture): - context = context_fixture['context'] - cache_home = context_fixture['xdg-cache'] - assert(isinstance(context, Context)) - - context.load(config=os.devnull) - assert(context.sourcedir == os.path.join(cache_home, 'buildstream', 'sources')) - assert(context.builddir == os.path.join(cache_home, 'buildstream', 'build')) - assert(context.artifactdir == os.path.join(cache_home, 'buildstream', 'artifacts')) - assert(context.logdir == os.path.join(cache_home, 'buildstream', 'logs')) - - -# Assert that a changed XDG_CACHE_HOME doesn't cause issues -def test_context_load_envvar(context_fixture): - os.environ['XDG_CACHE_HOME'] = '/some/path/' - - context = context_fixture['context'] - assert(isinstance(context, Context)) - - context.load(config=os.devnull) - assert(context.sourcedir == os.path.join('/', 'some', 'path', 'buildstream', 'sources')) - assert(context.builddir == os.path.join('/', 'some', 'path', 'buildstream', 'build')) - assert(context.artifactdir == os.path.join('/', 'some', 'path', 'buildstream', 'artifacts')) - assert(context.logdir == os.path.join('/', 'some', 'path', 'buildstream', 'logs')) - - # Reset the environment variable - del os.environ['XDG_CACHE_HOME'] - - -# Test that values in a user specified config file -# override the defaults -@pytest.mark.datafiles(os.path.join(DATA_DIR)) -def test_context_load_user_config(context_fixture, datafiles): - context = context_fixture['context'] - cache_home = context_fixture['xdg-cache'] - assert(isinstance(context, Context)) - - conf_file = os.path.join(datafiles.dirname, - datafiles.basename, - 'userconf.yaml') - context.load(conf_file) - - assert(context.sourcedir == os.path.expanduser('~/pony')) - assert(context.builddir == os.path.join(cache_home, 'buildstream', 'build')) - assert(context.artifactdir == os.path.join(cache_home, 'buildstream', 'artifacts')) - assert(context.logdir == os.path.join(cache_home, 'buildstream', 'logs')) - - -####################################### -# Test failure modes # -####################################### -@pytest.mark.datafiles(os.path.join(DATA_DIR)) -def test_context_load_missing_config(context_fixture, datafiles): - context = context_fixture['context'] - assert(isinstance(context, Context)) - - conf_file = os.path.join(datafiles.dirname, - datafiles.basename, - 'nonexistant.yaml') - - with pytest.raises(LoadError) as exc: - context.load(conf_file) - - assert (exc.value.reason == LoadErrorReason.MISSING_FILE) - - -@pytest.mark.datafiles(os.path.join(DATA_DIR)) -def test_context_load_malformed_config(context_fixture, datafiles): - context = context_fixture['context'] - assert(isinstance(context, Context)) - - conf_file = os.path.join(datafiles.dirname, - datafiles.basename, - 'malformed.yaml') - - with pytest.raises(LoadError) as exc: - context.load(conf_file) - - assert (exc.value.reason == LoadErrorReason.INVALID_YAML) - - -@pytest.mark.datafiles(os.path.join(DATA_DIR)) -def test_context_load_notdict_config(context_fixture, datafiles): - context = context_fixture['context'] - assert(isinstance(context, Context)) - - conf_file = os.path.join(datafiles.dirname, - datafiles.basename, - 'notdict.yaml') - - with pytest.raises(LoadError) as exc: - context.load(conf_file) - - # XXX Should this be a different LoadErrorReason ? - assert (exc.value.reason == LoadErrorReason.INVALID_YAML) diff --git a/tests/context/data/malformed.yaml b/tests/context/data/malformed.yaml deleted file mode 100644 index 88d1960b4..000000000 --- a/tests/context/data/malformed.yaml +++ /dev/null @@ -1,4 +0,0 @@ -- | - this is malformed yaml. - -** diff --git a/tests/context/data/notdict.yaml b/tests/context/data/notdict.yaml deleted file mode 100644 index e15deca98..000000000 --- a/tests/context/data/notdict.yaml +++ /dev/null @@ -1 +0,0 @@ -This is not a dict. diff --git a/tests/context/data/userconf.yaml b/tests/context/data/userconf.yaml deleted file mode 100644 index e8e72d5ce..000000000 --- a/tests/context/data/userconf.yaml +++ /dev/null @@ -1,3 +0,0 @@ -# Try overriding something - -sourcedir: ~/pony diff --git a/tests/internals/context.py b/tests/internals/context.py new file mode 100644 index 000000000..5a4b37ac5 --- /dev/null +++ b/tests/internals/context.py @@ -0,0 +1,132 @@ +import os +import pytest + +from buildstream._context import Context +from buildstream._exceptions import LoadError, LoadErrorReason + +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + 'context', +) + + +# Simple fixture to create a Context object. +@pytest.fixture() +def context_fixture(): + if os.environ.get('XDG_CACHE_HOME'): + cache_home = os.environ['XDG_CACHE_HOME'] + else: + cache_home = os.path.expanduser('~/.cache') + + return { + 'xdg-cache': cache_home, + 'context': Context() + } + + +####################################### +# Test instantiation # +####################################### +def test_context_create(context_fixture): + context = context_fixture['context'] + assert(isinstance(context, Context)) + + +####################################### +# Test configuration loading # +####################################### +def test_context_load(context_fixture): + context = context_fixture['context'] + cache_home = context_fixture['xdg-cache'] + assert(isinstance(context, Context)) + + context.load(config=os.devnull) + assert(context.sourcedir == os.path.join(cache_home, 'buildstream', 'sources')) + assert(context.builddir == os.path.join(cache_home, 'buildstream', 'build')) + assert(context.artifactdir == os.path.join(cache_home, 'buildstream', 'artifacts')) + assert(context.logdir == os.path.join(cache_home, 'buildstream', 'logs')) + + +# Assert that a changed XDG_CACHE_HOME doesn't cause issues +def test_context_load_envvar(context_fixture): + os.environ['XDG_CACHE_HOME'] = '/some/path/' + + context = context_fixture['context'] + assert(isinstance(context, Context)) + + context.load(config=os.devnull) + assert(context.sourcedir == os.path.join('/', 'some', 'path', 'buildstream', 'sources')) + assert(context.builddir == os.path.join('/', 'some', 'path', 'buildstream', 'build')) + assert(context.artifactdir == os.path.join('/', 'some', 'path', 'buildstream', 'artifacts')) + assert(context.logdir == os.path.join('/', 'some', 'path', 'buildstream', 'logs')) + + # Reset the environment variable + del os.environ['XDG_CACHE_HOME'] + + +# Test that values in a user specified config file +# override the defaults +@pytest.mark.datafiles(os.path.join(DATA_DIR)) +def test_context_load_user_config(context_fixture, datafiles): + context = context_fixture['context'] + cache_home = context_fixture['xdg-cache'] + assert(isinstance(context, Context)) + + conf_file = os.path.join(datafiles.dirname, + datafiles.basename, + 'userconf.yaml') + context.load(conf_file) + + assert(context.sourcedir == os.path.expanduser('~/pony')) + assert(context.builddir == os.path.join(cache_home, 'buildstream', 'build')) + assert(context.artifactdir == os.path.join(cache_home, 'buildstream', 'artifacts')) + assert(context.logdir == os.path.join(cache_home, 'buildstream', 'logs')) + + +####################################### +# Test failure modes # +####################################### +@pytest.mark.datafiles(os.path.join(DATA_DIR)) +def test_context_load_missing_config(context_fixture, datafiles): + context = context_fixture['context'] + assert(isinstance(context, Context)) + + conf_file = os.path.join(datafiles.dirname, + datafiles.basename, + 'nonexistant.yaml') + + with pytest.raises(LoadError) as exc: + context.load(conf_file) + + assert (exc.value.reason == LoadErrorReason.MISSING_FILE) + + +@pytest.mark.datafiles(os.path.join(DATA_DIR)) +def test_context_load_malformed_config(context_fixture, datafiles): + context = context_fixture['context'] + assert(isinstance(context, Context)) + + conf_file = os.path.join(datafiles.dirname, + datafiles.basename, + 'malformed.yaml') + + with pytest.raises(LoadError) as exc: + context.load(conf_file) + + assert (exc.value.reason == LoadErrorReason.INVALID_YAML) + + +@pytest.mark.datafiles(os.path.join(DATA_DIR)) +def test_context_load_notdict_config(context_fixture, datafiles): + context = context_fixture['context'] + assert(isinstance(context, Context)) + + conf_file = os.path.join(datafiles.dirname, + datafiles.basename, + 'notdict.yaml') + + with pytest.raises(LoadError) as exc: + context.load(conf_file) + + # XXX Should this be a different LoadErrorReason ? + assert (exc.value.reason == LoadErrorReason.INVALID_YAML) diff --git a/tests/internals/context/malformed.yaml b/tests/internals/context/malformed.yaml new file mode 100644 index 000000000..88d1960b4 --- /dev/null +++ b/tests/internals/context/malformed.yaml @@ -0,0 +1,4 @@ +- | + this is malformed yaml. + +** diff --git a/tests/internals/context/notdict.yaml b/tests/internals/context/notdict.yaml new file mode 100644 index 000000000..e15deca98 --- /dev/null +++ b/tests/internals/context/notdict.yaml @@ -0,0 +1 @@ +This is not a dict. diff --git a/tests/internals/context/userconf.yaml b/tests/internals/context/userconf.yaml new file mode 100644 index 000000000..e8e72d5ce --- /dev/null +++ b/tests/internals/context/userconf.yaml @@ -0,0 +1,3 @@ +# Try overriding something + +sourcedir: ~/pony -- cgit v1.2.1