From f392caa9b278c672e8308c0265b7c65ab881c2bc Mon Sep 17 00:00:00 2001 From: Shyue Ping Ong Date: Tue, 1 Aug 2023 20:47:21 -0700 Subject: [PATCH] Remove code with no tests. Add test for one piece of code. --- monty/inspect.py | 35 +---------------------------------- tests/test_itertools.py | 21 +++++++++------------ 2 files changed, 10 insertions(+), 46 deletions(-) diff --git a/monty/inspect.py b/monty/inspect.py index e3c718cc4..8172d4a96 100644 --- a/monty/inspect.py +++ b/monty/inspect.py @@ -4,8 +4,7 @@ import inspect import os -from functools import wraps -from inspect import currentframe, getframeinfo, getfullargspec +from inspect import currentframe, getframeinfo def all_subclasses(cls): @@ -68,35 +67,3 @@ def caller_name(skip=2): name.append(codename) # function or a method del parentframe return ".".join(name) - - -def initializer(func): - """ - Automatically assigns the parameters. - http://stackoverflow.com/questions/1389180/python-automatically-initialize - -instance-variables - - >>> class process: - ... @initializer - ... def __init__(self, cmd, reachable=False, user='root'): - ... pass - >>> p = process('halt', True) - >>> p.cmd, p.reachable, p.user - ('halt', True, 'root') - """ - names, varargs, keywords, defaults = getfullargspec(func) # type: ignore - - @wraps(func) - def wrapper(self, *args, **kargs): - for name, arg in list(zip(names[1:], args)) + list(kargs.items()): - setattr(self, name, arg) - - # Avoid TypeError: argument to reversed() must be a sequence - if defaults is not None: - for name, default in zip(reversed(names), reversed(defaults)): - if not hasattr(self, name): - setattr(self, name, default) - - return func(self, *args, **kargs) - - return wrapper diff --git a/tests/test_itertools.py b/tests/test_itertools.py index 77440e2a3..26a14882d 100644 --- a/tests/test_itertools.py +++ b/tests/test_itertools.py @@ -1,19 +1,16 @@ # Copyright (c) Materials Virtual Lab. # Distributed under the terms of the BSD License. -""" -#TODO: Replace with proper module doc. -""" +from monty.itertools import chunks, iterator_from_slice -import unittest -from monty.itertools import iterator_from_slice +def test_iterator_from_slice(): + assert list(iterator_from_slice(slice(0, 6, 2))) == [0, 2, 4] -class FuncTest(unittest.TestCase): - def test_iterator_from_slice(self): - self.assertEqual(list(iterator_from_slice(slice(0, 6, 2))), [0, 2, 4]) - - -if __name__ == "__main__": - unittest.main() +def test_chunks(): + assert list(chunks(range(1, 25), 10)) == [ + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), + (11, 12, 13, 14, 15, 16, 17, 18, 19, 20), + (21, 22, 23, 24), + ]