Skip to content

Commit

Permalink
Remove code with no tests. Add test for one piece of code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyue Ping Ong committed Aug 2, 2023
1 parent 6eb73b8 commit f392caa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 46 deletions.
35 changes: 1 addition & 34 deletions monty/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
21 changes: 9 additions & 12 deletions tests/test_itertools.py
Original file line number Diff line number Diff line change
@@ -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),
]

0 comments on commit f392caa

Please sign in to comment.