This repository has been archived by the owner on Feb 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(pipeline): test pipeline load from yaml
- Loading branch information
hanhxiao
committed
Aug 30, 2019
1 parent
8524b1f
commit d4f69ef
Showing
7 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from gnes.component import BaseEncoder | ||
from gnes.helper import train_required | ||
|
||
|
||
class DummyEncoder2(BaseEncoder): | ||
|
||
def train(self, *args, **kwargs): | ||
self.logger.info('you just trained me!') | ||
pass | ||
|
||
@train_required | ||
def encode(self, x): | ||
return x + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from gnes.component import BaseEncoder | ||
from gnes.helper import train_required | ||
|
||
|
||
class DummyEncoder3(BaseEncoder): | ||
|
||
def train(self, *args, **kwargs): | ||
self.logger.info('you just trained me!') | ||
pass | ||
|
||
@train_required | ||
def encode(self, x): | ||
return x + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
import unittest | ||
|
||
from gnes.encoder.base import BaseEncoder | ||
from gnes.helper import PathImporter | ||
|
||
|
||
class TestPipeTrain(unittest.TestCase): | ||
def setUp(self): | ||
self.dirname = os.path.dirname(__file__) | ||
PathImporter.add_modules(*('{0}/contrib/dummy2.py,{0}/contrib/dummy3.py'.format(self.dirname).split(','))) | ||
|
||
def tearDown(self): | ||
if os.path.exists('dummy-pipeline.bin'): | ||
os.remove('dummy-pipeline.bin') | ||
if os.path.exists('dummy-pipeline.yml'): | ||
os.remove('dummy-pipeline.yml') | ||
|
||
def test_load_yaml(self): | ||
p = BaseEncoder.load_yaml(os.path.join(self.dirname, 'yaml', 'pipeline-multi-encoder2.yml')) | ||
self.assertFalse(p.is_trained) | ||
self.assertRaises(RuntimeError, p.encode, 1) | ||
p.train(1) | ||
self.assertTrue(p.is_trained) | ||
self.assertEqual(5, p.encode(1)) | ||
p = BaseEncoder.load_yaml(os.path.join(self.dirname, 'yaml', 'pipeline-multi-encoder2.yml')) | ||
self.assertRaises(RuntimeError, p.encode, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
!PipelineEncoder | ||
components: | ||
- !DummyEncoder2 | ||
gnes_config: | ||
is_trained: true | ||
- !DummyEncoder2 {} | ||
- !DummyEncoder3 {} | ||
- !DummyEncoder3 {} | ||
gnes_config: | ||
name: dummy-pipeline |