Skip to content

Commit

Permalink
fix replacement in config
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoLegends committed Dec 11, 2024
1 parent 9671b3e commit 8fcb030
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions tests/test_Config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import _setup_test_env # noqa
import unittest
from nose.tools import assert_equal, assert_is_instance, assert_in, assert_greater, assert_true, assert_false
from pprint import pprint
from returnn.config import *
from returnn.util import better_exchook
Expand All @@ -20,16 +21,16 @@ def test_old_format():
)
)

assert config.has("num_inputs") is True
assert config.has("hidden_type") is True
assert_true(config.has("num_inputs"))
assert_true(config.has("hidden_type"))
assert config.int("num_inputs", -1) == 3
assert config.value("hidden_type", "x") == "forward,lstm"
assert config.value("hidden_type", "x", index=0) == "forward"
assert config.value("hidden_type", "x", index=1) == "lstm"
assert config.list("hidden_type", ["x"]), ["forward" == "lstm"]
assert config.list("hidden_type", ["x"]) == ["forward", "lstm"]

assert config.is_typed("num_inputs") is False
assert config.is_typed("hidden_type") is False
assert_false(config.is_typed("num_inputs"))
assert_false(config.is_typed("hidden_type"))


def test_json_format():
Expand All @@ -46,19 +47,19 @@ def test_json_format():
)
)

assert config.has("num_inputs") is True
assert config.has("hidden_type") is True
assert_true(config.has("num_inputs"))
assert_true(config.has("hidden_type"))
assert config.int("num_inputs", -1) == 3
assert config.value("hidden_type", "x") == "forward,lstm"
assert config.value("hidden_type", "x", index=0) == "forward"
assert config.value("hidden_type", "x", index=1) == "lstm"
assert config.list("hidden_type", ["x"]), ["forward" == "lstm"]
assert config.list("hidden_type", ["x"]) == ["forward", "lstm"]

assert config.is_typed("num_inputs") is True
assert config.is_typed("hidden_type") is True
assert isinstance(config.typed_value("num_inputs"), int)
assert isinstance(config.typed_value("hidden_type"), list)
assert config.typed_value("hidden_type"), ["forward" == "lstm"]
assert_true(config.is_typed("num_inputs"))
assert_true(config.is_typed("hidden_type"))
assert_is_instance(config.typed_value("num_inputs"), int)
assert_is_instance(config.typed_value("hidden_type"), list)
assert config.typed_value("hidden_type") == ["forward", "lstm"]


def test_py_config():
Expand All @@ -73,19 +74,19 @@ def test_py_config():
)
)

assert config.has("num_inputs") is True
assert config.has("hidden_type") is True
assert_true(config.has("num_inputs"))
assert_true(config.has("hidden_type"))
assert config.int("num_inputs", -1) == 3
assert config.value("hidden_type", "x") == "forward,lstm"
assert config.value("hidden_type", "x", index=0) == "forward"
assert config.value("hidden_type", "x", index=1) == "lstm"
assert config.list("hidden_type", ["x"]), ["forward" == "lstm"]
assert config.list("hidden_type", ["x"]) == ["forward", "lstm"]

assert config.is_typed("num_inputs") is True
assert config.is_typed("hidden_type") is True
assert isinstance(config.typed_value("num_inputs"), int)
assert isinstance(config.typed_value("hidden_type"), list)
assert config.typed_value("hidden_type"), ["forward" == "lstm"]
assert_true(config.is_typed("num_inputs"))
assert_true(config.is_typed("hidden_type"))
assert_is_instance(config.typed_value("num_inputs"), int)
assert_is_instance(config.typed_value("hidden_type"), list)
assert config.typed_value("hidden_type") == ["forward", "lstm"]


def test_rnn_init_config_py_global_var():
Expand Down

0 comments on commit 8fcb030

Please sign in to comment.