Skip to content

Commit

Permalink
Merge pull request #90 from jacebrowning/fix-flaky
Browse files Browse the repository at this point in the history
Convert flaky integration test to unit tests
  • Loading branch information
jacebrowning committed Jan 10, 2019
2 parents c73fb7c + fa3526f commit 6a26aa6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 107 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test: install ## Run unit and integration tests

.PHONY: test-repeat
test-repeat: install
poetry run pytest --count=5 --random
poetry run pytest --count=5 --random --exitfirst

.PHONY: test-profile
test-profile: install
Expand Down
28 changes: 28 additions & 0 deletions datafiles/tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import ByteString, Dict, List, Optional

import pytest
from ruamel.yaml.scalarstring import LiteralScalarString

from datafiles import converters

Expand All @@ -26,6 +27,10 @@ class MyNonDataclass:


def describe_map_type():
def it_handles_extended_types(expect):
converter = converters.map_type(converters.Number)
expect(converter.__name__) == 'Number'

def it_handles_list_annotations(expect):
converter = converters.map_type(List[str])
expect(converter.__name__) == 'StringList'
Expand Down Expand Up @@ -116,6 +121,17 @@ def describe_to_python_value():
def when_nominal(expect, converter, data, value):
expect(converter.to_python_value(data, target=None)) == value

def when_number(expect):
convert = converters.Number.to_python_value
expect(convert(1.23)).isinstance(float)
expect(convert(42)).isinstance(int)

def when_text(expect):
convert = converters.Text.to_python_value
expect(convert("")) == ""
expect(convert("Hello, world!")) == "Hello, world!"
expect(convert("Line 1\nLine 2\n")) == "Line 1\nLine 2\n"

def when_invalid(expect):
message = "invalid literal for int() with base 10: 'a'"
with expect.raises(ValueError, message):
Expand Down Expand Up @@ -180,6 +196,18 @@ def describe_to_preserialization_data():
def when_nominal(expect, converter, value, data):
expect(converter.to_preserialization_data(value)) == data

def when_number(expect):
convert = converters.Number.to_preserialization_data
expect(convert(1.23)).isinstance(float)
expect(convert(42)).isinstance(int)

def when_text(expect):
convert = converters.Text.to_preserialization_data
expect(convert("")) == ""
expect(convert("Hello, world!")) == "Hello, world!"
expect(convert("Line 1\nLine 2")) == "Line 1\nLine 2\n"
expect(convert("Line 1\nLine 2")).isinstance(LiteralScalarString)

def when_invalid(expect):
message = "invalid literal for int() with base 10: 'a'"
with expect.raises(ValueError, message):
Expand Down
106 changes: 0 additions & 106 deletions tests/test_types.py

This file was deleted.

0 comments on commit 6a26aa6

Please sign in to comment.