Skip to content

Commit

Permalink
added docs for resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
ncilfone committed May 17, 2022
1 parent fdb286f commit 18b48fc
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 14 deletions.
14 changes: 4 additions & 10 deletions .github/ISSUE_TEMPLATE/bug_report.md
Expand Up @@ -23,16 +23,10 @@ A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Environment (please complete the following information):**
- OS: [e.g. Ubuntu 16.04, Windows, etc.]
- Python version [e.g. 3.6.3, 3.7.5]:
- Other installed packages [e.g. torch, scipy, etc.]

**Additional context**
Add any other context about the problem here.
3 changes: 2 additions & 1 deletion .github/pull_request_template.md
Expand Up @@ -12,7 +12,8 @@ E.g. Describe the added feature or what issue it fixes #(issue)...
- [ ] Did you run black and isort prior to submitting your PR?
- [ ] Does your PR pass all existing unit tests?
- [ ] Did you add associated unit tests for any additional functionality?
- [ ] Did you provide documentation ([Google Docstring format](https://google.github.io/styleguide/pyguide.html)) whenever possible, even for simple functions or classes?
- [ ] Did you provide code documentation ([Google Docstring format](https://google.github.io/styleguide/pyguide.html)) whenever possible, even for simple functions or classes?
- [ ] Did you add necessary documentation to the website?

## Review
Request will go to reviewers to approve for merge.
72 changes: 69 additions & 3 deletions tests/base/test_resolvers.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
import sys
import datetime
import os
import re
import sys

import attr
import pytest

from spock import spock
Expand Down Expand Up @@ -197,7 +198,7 @@ def arg_builder_conf(monkeypatch):
os.environ["BOOL"] = "true"
os.environ["STRING"] = "boo"
config = SpockBuilder(EnvClass)
return config.generate()
return config.generate(), config

@staticmethod
@pytest.fixture
Expand Down Expand Up @@ -227,6 +228,70 @@ def crypto_builder_yaml(monkeypatch):
key='./tests/conf/yaml/test_key.yaml')
return config.generate()

def test_saver_with_resolvers(self, monkeypatch, tmp_path):
with monkeypatch.context() as m:
m.setattr(sys, "argv", ["", "--config", "./tests/conf/yaml/test_resolvers.yaml"])
os.environ['INT'] = "2"
os.environ['FLOAT'] = "2.0"
os.environ["BOOL"] = "true"
os.environ["STRING"] = "boo"
config = SpockBuilder(EnvClass)
now = datetime.datetime.now()
curr_int_time = int(f"{now.year}{now.month}{now.day}{now.hour}{now.second}")
config_values = config.save(
file_extension=".yaml",
file_name=f"pytest.{curr_int_time}",
user_specified_path=tmp_path
).generate()
yaml_regex = re.compile(
fr"pytest.{curr_int_time}."
fr"[a-fA-F0-9]{{8}}-[a-fA-F0-9]{{4}}-[a-fA-F0-9]{{4}}-"
fr"[a-fA-F0-9]{{4}}-[a-fA-F0-9]{{12}}.spock.cfg.yaml"
)
yaml_key_regex = re.compile(
fr"pytest.{curr_int_time}."
fr"[a-fA-F0-9]{{8}}-[a-fA-F0-9]{{4}}-[a-fA-F0-9]{{4}}-"
fr"[a-fA-F0-9]{{4}}-[a-fA-F0-9]{{12}}.spock.cfg.key.yaml"
)
yaml_salt_regex = re.compile(
fr"pytest.{curr_int_time}."
fr"[a-fA-F0-9]{{8}}-[a-fA-F0-9]{{4}}-[a-fA-F0-9]{{4}}-"
fr"[a-fA-F0-9]{{4}}-[a-fA-F0-9]{{12}}.spock.cfg.salt.yaml"
)
matches = [
re.fullmatch(yaml_regex, val)
for val in os.listdir(str(tmp_path))
if re.fullmatch(yaml_regex, val) is not None
]

key_matches = [
re.fullmatch(yaml_key_regex, val)
for val in os.listdir(str(tmp_path))
if re.fullmatch(yaml_key_regex, val) is not None
]
assert len(key_matches) == 1 and key_matches[0] is not None
salt_matches = [
re.fullmatch(yaml_salt_regex, val)
for val in os.listdir(str(tmp_path))
if re.fullmatch(yaml_salt_regex, val) is not None
]
assert len(salt_matches) == 1 and salt_matches[0] is not None
fname = f"{str(tmp_path)}/{matches[0].string}"
keyname = f"{str(tmp_path)}/{key_matches[0].string}"
saltname = f"{str(tmp_path)}/{salt_matches[0].string}"

# Deserialize
m.setattr(
sys, "argv", ["", "--config", f"{fname}"]
)
de_serial_config = SpockBuilder(
EnvClass,
desc="Test Builder",
key=keyname,
salt=saltname
).generate()
assert config_values == de_serial_config

def test_crypto_from_direct_api(self, crypto_builder_direct_api):
assert crypto_builder_direct_api.FromCrypto.env_int_def_from_crypto == 100
assert crypto_builder_direct_api.FromCrypto.env_float_def_from_crypto == 100.0
Expand Down Expand Up @@ -273,6 +338,7 @@ def test_resolver_basic_no_conf(self, arg_builder_no_conf):
assert arg_builder_no_conf.EnvClass.env_str_def_opt is None

def test_resolver_basic_conf(self, arg_builder_conf):
arg_builder_conf, _ = arg_builder_conf
# Basic types no defaults
assert arg_builder_conf.EnvClass.env_int == 2
assert arg_builder_conf.EnvClass.env_float == 2.0
Expand Down

0 comments on commit 18b48fc

Please sign in to comment.