Skip to content

Commit

Permalink
Remove unused compiler function cast_to_numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobGM committed May 4, 2018
1 parent 91f36ba commit 589b228
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 97 deletions.
34 changes: 1 addition & 33 deletions astrality/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import shutil
from functools import partial
from pathlib import Path
from typing import Any, Dict, Optional, Union
from typing import Any, Dict, Optional

from jinja2 import (
Environment,
Expand All @@ -23,38 +23,6 @@
logger = logging.getLogger('astrality')


def cast_to_numeric(value: str) -> Union[int, float, str]:
"""Casts string to numeric type if possible, else return string."""
try:
return int(value)
except ValueError:
try:
return float(value)
except ValueError:
return value


def context(config: ApplicationConfig) -> Context:
"""
Return a context dictionary based on the contents of a config dict.
Only sections named context/* are considered to be context sections, and
these sections are returned with 'context/' stripped away, and with their
contents cast to a Context instance.
"""
contents: Context = Context()
for section_name, section in config.items():
if not isinstance(section_name, str) or \
not len(section_name) > 8 or \
not section_name[:8].lower() == 'context/':
continue
else:
category = section_name[8:]
contents[category] = Context(section)

return contents


def jinja_environment(
templates_folder: Path,
shell_command_working_directory: Path,
Expand Down
15 changes: 1 addition & 14 deletions astrality/tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
from pathlib import Path

import pytest
from jinja2 import Environment, UndefinedError
from jinja2 import UndefinedError

from astrality.compiler import (
cast_to_numeric,
compile_template,
compile_template_to_string,
jinja_environment,
Expand Down Expand Up @@ -60,18 +59,6 @@ def test_compilation_of_jinja_template(test_templates_folder, expanded_env_dict)
with open(target) as target:
assert target.read() == 'test_value\nfallback_value\n'

@pytest.mark.parametrize(('string,cast,resulting_type'), [
('-2', -2, int),
('0', 0, int),
('1', 1, int),
('1.5', 1.5, float),
('one', 'one', str),
])
def test_cast_to_numeric(string, cast, resulting_type):
result = cast_to_numeric(string)
assert result == cast
assert isinstance(result, resulting_type)


def test_run_shell_template_filter(test_templates_folder):
shell_template_path = test_templates_folder / 'shell_filter.template'
Expand Down
50 changes: 0 additions & 50 deletions astrality/tests/test_compiler_context.py

This file was deleted.

0 comments on commit 589b228

Please sign in to comment.