Skip to content

Commit

Permalink
Remove ruamel.yaml test dependency (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesgranger authored Oct 29, 2019
1 parent 0b3742c commit d9fa2ad
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
1 change: 0 additions & 1 deletion test_requirements.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
docker~=4.0
pytest~=5.2
pytest-xdist~=1.26 # Parallelises the test-runs
ruamel.yaml~=0.15
pytest-mock~=1.11
pytest-mypy~=0.3
pytest-timeout~=1.3
Expand Down
2 changes: 0 additions & 2 deletions test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ qtconsole==4.5.5 # via jupyter
regex==2019.8.19 # via black
requests==2.22.0 # via adal, docker, responses
responses==0.10.6
ruamel.yaml.clib==0.2.0 # via ruamel.yaml
ruamel.yaml==0.16.5
scikit-learn==0.21.3
scipy==1.3.1 # via scikit-learn
send2trash==1.5.0 # via notebook
Expand Down
7 changes: 3 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import docker
import pytest
import requests
import ruamel.yaml
import yaml
import numpy as np

from gordo_components import serializer
Expand Down Expand Up @@ -92,7 +92,7 @@ def trained_model_directory(
model_dir = os.path.join(collection_dir, gordo_name)
os.makedirs(model_dir, exist_ok=True)

definition = ruamel.yaml.load(
definition = yaml.safe_load(
"""
gordo_components.model.anomaly.diff.DiffBasedAnomalyDetector:
base_estimator:
Expand All @@ -102,8 +102,7 @@ def trained_model_directory(
- gordo_components.model.models.KerasAutoEncoder:
kind: feedforward_hourglass
memory:
""",
Loader=ruamel.yaml.Loader,
"""
)
model = serializer.pipeline_from_definition(definition)
X = np.random.random(size=len(sensors) * 10).reshape(10, len(sensors))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import unittest
import logging
import ruamel.yaml
import io
import yaml
import json
import pydoc

from sklearn.pipeline import Pipeline, FeatureUnion
Expand Down Expand Up @@ -123,32 +123,31 @@ def setUp(self):

def test_pipeline_into_definition(self):

expected_definition = (
"""
expected_definition = """
sklearn.pipeline.Pipeline:
memory:
memory: null
steps:
- sklearn.decomposition.pca.PCA:
copy: true
iterated_power: auto
n_components: 2
random_state:
random_state: null
svd_solver: auto
tol: 0.0
whiten: false
- sklearn.pipeline.FeatureUnion:
n_jobs:
n_jobs: null
transformer_list:
- sklearn.decomposition.pca.PCA:
copy: true
iterated_power: auto
n_components: 3
random_state:
random_state: null
svd_solver: auto
tol: 0.0
whiten: false
- sklearn.pipeline.Pipeline:
memory:
memory: null
steps:
- sklearn.preprocessing.data.MinMaxScaler:
copy: true
Expand All @@ -159,33 +158,28 @@ def test_pipeline_into_definition(self):
algorithm: randomized
n_components: 2
n_iter: 5
random_state:
random_state: null
tol: 0.0
verbose: false
transformer_weights:
transformer_weights: null
verbose: false
- gordo_components.model.models.KerasAutoEncoder:
kind: feedforward_hourglass
verbose: false
""".rstrip()
.strip()
.replace(" ", "")
)
"""

for pipe in self.variations_of_same_pipeline:
expected_definition = yaml.safe_load(expected_definition)

definition = pipeline_into_definition(pipe)
for pipe in self.variations_of_same_pipeline:

# Using ruamel over PyYaml, better output option support
stream = io.StringIO()
ruamel.yaml.dump(definition, stream, Dumper=ruamel.yaml.RoundTripDumper)
stream.seek(0)
definition = pipeline_into_definition(
pipeline_from_definition(pipeline_into_definition(pipe))
)

current_output = stream.read().rstrip().strip().replace(" ", "")
self.assertEqual(
current_output,
expected_definition,
msg=f"Failed output:\n{current_output}\nExpected:----------------\n{expected_definition}",
json.dumps(definition),
json.dumps(expected_definition),
msg=f"Failed output:\n{definition}\nExpected:----------------\n{expected_definition}",
)

def test_into_from(self):
Expand Down Expand Up @@ -296,7 +290,7 @@ def test_from_into(self):
memory:
verbose: false
"""
definition = ruamel.yaml.load(definition, Loader=ruamel.yaml.Loader)
definition = yaml.safe_load(definition)
pipe = pipeline_from_definition(definition)
pipeline_into_definition(pipe)

Expand Down

0 comments on commit d9fa2ad

Please sign in to comment.