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

Commit e355e86

Browse files
John Andersenpdxjohnny
John Andersen
authored andcommitted
util: testing: test_label for file sources
Signed-off-by: John Andersen <[email protected]>
1 parent 75103bb commit e355e86

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Async helper concurrently nocancel optional keyword argument which, if set is
1010
a set of tasks not to cancel when the concurrently execution loop completes.
11+
- FileSourceTest has a `test_label` method which checks that a FileSource knows
12+
how to properly load and save repos under a given label.
1113
### Changed
1214
- feature/codesec became it's own branch, binsec
1315
- BaseOrchestratorContext `run_operations` strict is default to true. With

dffml/util/testing/source.py

+16
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,19 @@ async def test_update(self):
118118
testdir, str(random.random) + "." + extension
119119
)
120120
await super().test_update()
121+
122+
async def test_label(self):
123+
with tempfile.TemporaryDirectory() as testdir:
124+
self.testfile = os.path.join(testdir, str(random.random))
125+
unlabeled = await self.setUpSource()
126+
labeled = await self.setUpSource()
127+
labeled.config = labeled.config._replace(label="somelabel")
128+
async with unlabeled:
129+
async with unlabeled() as uctx:
130+
await uctx.update(
131+
Repo("0", data={"features": {"life": 42}})
132+
)
133+
async with labeled:
134+
async with labeled() as lctx:
135+
repo = await lctx.repo("0")
136+
self.assertNotIn("life", repo.features())

examples/source/test_custom_sqlite.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
from dffml.util.testing.source import SourceTest
1+
import unittest
2+
3+
from dffml.util.testing.source import FileSourceTest
24
from dffml.util.asynctestcase import AsyncTestCase
35

46
from .custom_sqlite import CustomSQLiteSourceConfig, CustomSQLiteSource
57

68

7-
class TestJSONSource(SourceTest, AsyncTestCase):
8-
async def setUpFile(self, fileobj):
9-
return
10-
fileobj.write(b"{}")
11-
fileobj.seek(0)
12-
13-
async def setUpSource(self, fileobj):
9+
class TestJSONSource(FileSourceTest, AsyncTestCase):
10+
async def setUpSource(self):
1411
return CustomSQLiteSource(
15-
CustomSQLiteSourceConfig(filename=fileobj.name)
12+
CustomSQLiteSourceConfig(filename=self.testfile)
1613
)
14+
15+
@unittest.skip("Labels not implemented")
16+
async def test_label(self):
17+
"""
18+
Labels not implemented
19+
"""

tests/source/test_csv.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# SPDX-License-Identifier: MIT
22
# Copyright (c) 2019 Intel Corporation
3+
import unittest
4+
35
from dffml.source.file import FileSourceConfig
46
from dffml.source.csv import CSVSource
57
from dffml.util.testing.source import FileSourceTest
@@ -9,3 +11,9 @@
911
class TestCSVSource(FileSourceTest, AsyncTestCase):
1012
async def setUpSource(self):
1113
return CSVSource(FileSourceConfig(filename=self.testfile))
14+
15+
@unittest.skip("Labels not implemented yet for CSV files")
16+
async def test_label(self):
17+
"""
18+
Labels not implemented yet for CSV files
19+
"""

tests/source/test_json.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77

88

99
class TestJSONSource(FileSourceTest, AsyncTestCase):
10-
1110
async def setUpSource(self):
1211
return JSONSource(FileSourceConfig(filename=self.testfile))

0 commit comments

Comments
 (0)