Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
util: testing: test_label for file sources
Browse files Browse the repository at this point in the history
Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
John Andersen authored and pdxjohnny committed Jun 14, 2019
1 parent 75103bb commit e355e86
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Async helper concurrently nocancel optional keyword argument which, if set is
a set of tasks not to cancel when the concurrently execution loop completes.
- FileSourceTest has a `test_label` method which checks that a FileSource knows
how to properly load and save repos under a given label.
### Changed
- feature/codesec became it's own branch, binsec
- BaseOrchestratorContext `run_operations` strict is default to true. With
Expand Down
16 changes: 16 additions & 0 deletions dffml/util/testing/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,19 @@ async def test_update(self):
testdir, str(random.random) + "." + extension
)
await super().test_update()

async def test_label(self):
with tempfile.TemporaryDirectory() as testdir:
self.testfile = os.path.join(testdir, str(random.random))
unlabeled = await self.setUpSource()
labeled = await self.setUpSource()
labeled.config = labeled.config._replace(label="somelabel")
async with unlabeled:
async with unlabeled() as uctx:
await uctx.update(
Repo("0", data={"features": {"life": 42}})
)
async with labeled:
async with labeled() as lctx:
repo = await lctx.repo("0")
self.assertNotIn("life", repo.features())
21 changes: 12 additions & 9 deletions examples/source/test_custom_sqlite.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
from dffml.util.testing.source import SourceTest
import unittest

from dffml.util.testing.source import FileSourceTest
from dffml.util.asynctestcase import AsyncTestCase

from .custom_sqlite import CustomSQLiteSourceConfig, CustomSQLiteSource


class TestJSONSource(SourceTest, AsyncTestCase):
async def setUpFile(self, fileobj):
return
fileobj.write(b"{}")
fileobj.seek(0)

async def setUpSource(self, fileobj):
class TestJSONSource(FileSourceTest, AsyncTestCase):
async def setUpSource(self):
return CustomSQLiteSource(
CustomSQLiteSourceConfig(filename=fileobj.name)
CustomSQLiteSourceConfig(filename=self.testfile)
)

@unittest.skip("Labels not implemented")
async def test_label(self):
"""
Labels not implemented
"""
8 changes: 8 additions & 0 deletions tests/source/test_csv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2019 Intel Corporation
import unittest

from dffml.source.file import FileSourceConfig
from dffml.source.csv import CSVSource
from dffml.util.testing.source import FileSourceTest
Expand All @@ -9,3 +11,9 @@
class TestCSVSource(FileSourceTest, AsyncTestCase):
async def setUpSource(self):
return CSVSource(FileSourceConfig(filename=self.testfile))

@unittest.skip("Labels not implemented yet for CSV files")
async def test_label(self):
"""
Labels not implemented yet for CSV files
"""
1 change: 0 additions & 1 deletion tests/source/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@


class TestJSONSource(FileSourceTest, AsyncTestCase):

async def setUpSource(self):
return JSONSource(FileSourceConfig(filename=self.testfile))

0 comments on commit e355e86

Please sign in to comment.