Skip to content

Commit

Permalink
Adds resources that I forgot to port over for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skrawcz committed Aug 21, 2020
2 parents 6113cce + 9f49906 commit c00663c
Show file tree
Hide file tree
Showing 19 changed files with 222 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# pre-commit hooks require a user to have installed `pre-commit`:
# $ brew install pre-commit
# Then install the hooks within the repo:
# $ cd /PATH/TO/Khan
# $ pre-commit install

repos:
- repo: git://github.com/pre-commit/mirrors-yapf
rev: v0.30.0
hooks:
- id: yapf
files: .py
args:
- -r

- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
# " -> '
- id: double-quote-string-fixer
# ensures files are either empty or end with a blank line
- id: end-of-file-fixer
# sorts requirements
- id: requirements-txt-fixer
# valid python file
- id: check-ast
23 changes: 23 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[style]
based_on_style = google

# max characters per line
COLUMN_LIMIT = 100

# Put closing brackets on a separate line, dedented, if the bracketed expression can't fit in a single line
DEDENT_CLOSING_BRACKETS = true

# Place each dictionary entry onto its own line.
EACH_DICT_ENTRY_ON_SEPARATE_LINE = true

# Join short lines into one line. E.g., single line if statements.
JOIN_MULTIPLE_LINES = true

# Insert a blank line before a def or class immediately nested within another def or class
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = true

# Split before arguments if the argument list is terminated by a comma.
SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED = true

# If an argument / parameter list is going to be split, then split before the first argument
SPLIT_BEFORE_FIRST_ARGUMENT = true
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pre-commit
3 changes: 3 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
pytest-assume
pytest-cov
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
graphviz
networkx
numpy
pandas
Empty file added tests/resources/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions tests/resources/bad_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Module for more dummy functions to test graph things with.
"""
# we import this to check we don't pull in this function when parsing this module.
from tests.resources import only_import_me


def A(b, c) -> int:
"""Should error out because we're missing an annotation"""
return b + c


def B(b: int, c: int):
"""Should error out because we're missing an annotation"""
return b + c


def C(b: int) -> dict:
"""Setting up type mismatch."""
return {'hi': 'world'}


def D(C: int) -> int:
"""C is the incorrect type."""
return int(C['hi'])
Empty file.
9 changes: 9 additions & 0 deletions tests/resources/config/default_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_VALUE = 'value'


def key() -> str:
return _VALUE


def double_key(key: str) -> str:
return key + key
2 changes: 2 additions & 0 deletions tests/resources/config/default_config_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def some_key() -> str:
return 'some_value'
5 changes: 5 additions & 0 deletions tests/resources/config/user_specified_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def key_overwrite_ignoring_input() -> str:
return 'user_specified_value'

def key_to_overwrite() -> str:
return 'user_specified_value'
25 changes: 25 additions & 0 deletions tests/resources/config_modifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from hamilton.function_modifiers import config


def new_param() -> str:
return 'dummy'


@config.when(fn_1_version=0)
def fn() -> str:
pass


@config.when(fn_1_version=1)
def fn__v1() -> str:
return 'version_1'


@config.when(fn_1_version=2)
def fn__v2(new_param: str) -> str:
return 'version_2'


@config.when(fn_1_version=3, name='fn')
def fn_to_rename() -> str:
return 'version_3'
25 changes: 25 additions & 0 deletions tests/resources/dummy_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Module for dummy functions to test graph things with.
"""
# we import this to check we don't pull in this function when parsing this module.
from tests.resources import only_import_me


def A(b: int, c: int) -> int:
"""Function that should become part of the graph - A"""
return b + c


def _do_not_import_me(some_input: int, some_input2: int) -> int:
"""Function that should not become part of the graph - _do_not_import_me."""
only_import_me.this_is_not_something_we_should_import()
return some_input + some_input2


def B(A: int) -> int:
"""Function that should become part of the graph - B"""
return A * A


def C(A: int) -> int: # empty string doc on purpose.
return A * 2
11 changes: 11 additions & 0 deletions tests/resources/extract_column_nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pandas as pd

from hamilton.function_modifiers import extract_columns


@extract_columns('col_1', 'col_2')
def generate_df() -> pd.DataFrame:
"""Function that should be parametrized to form multiple functions"""
return pd.DataFrame({
'col_1': [1, 2, 3],
'col_2': [4, 5, 6]})
5 changes: 5 additions & 0 deletions tests/resources/only_import_me.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Module for functions that we import in other test scenarios but never directly in the test case itself."""


def this_is_not_something_we_should_import():
print('Why am I being printed?')
7 changes: 7 additions & 0 deletions tests/resources/parametrized_nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from hamilton.function_modifiers import parametrized


@parametrized('param', {('parametrized_1', 'doc'): 1, ('parametrized_2', 'doc'): 2, ('parametrized_3', 'doc'): 3})
def to_parametrize(param: int) -> int:
"""Function that should be parametrized to form multiple functions"""
return param
17 changes: 17 additions & 0 deletions tests/resources/test_default_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Module for dummy functions to test graph things with.
"""


def A(required: int, defaults_to_zero: int = 0) -> int:
"""Function that should become part of the graph - A"""
return required + defaults_to_zero


def B(A: int) -> int:
"""Function that should become part of the graph - B"""
return A * A


def C(A: int) -> int: # empty string doc on purpose.
return A * 2
32 changes: 32 additions & 0 deletions tests/resources/typing_vs_not_typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Module for dummy functions to test graph things with.
"""
# we import this to check we don't pull in this function when parsing this module.
from tests.resources import only_import_me
from typing import Dict


def A(b: int, c: int) -> Dict:
"""Function that outputs a typing type."""
return {'a': b + c}


def _do_not_import_me(some_input: int, some_input2: int) -> int:
"""Function that should not become part of the graph - _do_not_import_me."""
only_import_me.this_is_not_something_we_should_import()
return some_input + some_input2


def B(A: dict) -> int:
"""Function that depends on A, but says it's a primitive type dict."""
return A['a'] + 1


def A2(x: int, y: int) -> dict:
"""Graph function using primitive output type."""
return {'a': x + y}


def B2(A2: Dict) -> int:
"""Graph function depending on A2 but saying it's a typing type."""
return A['a'] + 1
3 changes: 1 addition & 2 deletions tests/test_function_modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import pandas as pd
import pytest

from demandpy import models
from hamilton import function_modifiers
from hamilton import function_modifiers, models
from hamilton import node
from hamilton.function_modifiers import does, ensure_function_empty
from hamilton.node import DependencyType
Expand Down

0 comments on commit c00663c

Please sign in to comment.