Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Zhiyuan Chen <[email protected]>
  • Loading branch information
ZhiyuanChen committed Aug 26, 2024
1 parent 5ae148c commit 2733540
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@
from functools import partial
from io import StringIO

from pytest import raises

from chanfig import Config, Variable


class DataConfig(Config):
__test__ = False

def __init__(self, name, *args, **kwargs):
super().__init__()
self.name = name
self.max_length = 1024
self.merge(*args, **kwargs)
name: str
max_length: int = 1024

def post(self):
self.name = self.name.lower()
Expand Down Expand Up @@ -147,6 +145,14 @@ def test_copy(self):
assert config.copy() == copy(config)
assert config.deepcopy() == deepcopy(config)

def test_class_attribute(self):
config = TestConfig()
config.datas.a.name = "CIFAR100"
config.datas.b.name = "MNIST"
assert config.datas.a.max_length == config.datas.b.max_length == 1024
with raises(AttributeError):
config.datas.a.getattr("max_length")


class Ancestor(Config):
ancestor = 1
Expand Down
30 changes: 30 additions & 0 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# CHANfiG, Easier Configuration.
# Copyright (c) 2022-Present, CHANfiG Contributors

# This program is free software: you can redistribute it and/or modify
# it under the terms of the following licenses:
# - The Unlicense
# - GNU Affero General Public License v3.0 or later
# - GNU General Public License v2.0 or later
# - BSD 4-Clause "Original" or "Old" License
# - MIT License
# - Apache License 2.0

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the LICENSE file for more details.


from chanfig import ConfigRegistry as Registry_


class Registry(Registry_):
key = "level"


class TestRegistry:

def test_registry(self):
registry = Registry()
assert registry.getattr("key") == "level"

0 comments on commit 2733540

Please sign in to comment.