Repository: takahi-i/hideout

Issue:
Get class name for bind method for cache file

Discussion:

Patch:
diff --git a/hideout/file.py b/hideout/file.py
index 395e5d0..f204a37 100644
--- a/hideout/file.py
+++ b/hideout/file.py
@@ -66,11 +66,21 @@ def _generate_file_path_from_label(label):
 
 
 def _generate_file_path_from_func(func, func_args={}):
-    label = func.__name__
+    class_name = _get_class_that_defined_method(func)
+    label = "{}".format(class_name)
     for arg_name in func_args:
         arg_value = str(func_args[arg_name])
         if len(arg_value) > 10:
             arg_value = hashlib.md5(arg_value.encode("utf-8")).hexdigest()[0:10]
-            print("hashed_value: " + arg_value)
         label += "-{}-{}".format(arg_name, arg_value)
     return _generate_file_path_from_label(label)
+
+
+def _get_class_that_defined_method(method):
+    class_name = ""
+    names = method.__qualname__.split('.')
+    for i, attr in enumerate(names):
+        class_name += "{}".format(attr)
+        if i != len(names) - 1:
+            class_name += "-"
+    return class_name


Test patch:
diff --git a/tests/test_file.py b/tests/test_file.py
index 9e1d842..31ddb08 100644
--- a/tests/test_file.py
+++ b/tests/test_file.py
@@ -13,24 +13,40 @@ class Generator2:
         return {"foobar": baz}
 
 
+class Generator3:
+    class InnerGenerator:
+        def generate(self, baz):
+            return {"foobar": baz}
+
+    def __init__(self) -> None:
+        self.inner = Generator3.InnerGenerator()
+
+
 class TestFile(unittest.TestCase):
 
     def test_generate_file_name_with_label(self):
         self.assertEquals("large_object.pickle",
                           os.path.basename(generate_path(
-                            func=generate,
-                            func_args={"baz": [0, 1, 2, 3, 4, 5, 7, 6, 8, 9, 10]},
-                            label="large_object")))
+                              func=generate,
+                              func_args={"baz": [0, 1, 2, 3, 4, 5, 7, 6, 8, 9, 10]},
+                              label="large_object")))
 
     def test_generate_file_name_from_hash(self):
         self.assertEquals("generate-baz-6979983cbc.pickle",
                           os.path.basename(generate_path(
-                            func=generate,
-                            func_args={"baz": [0, 1, 2, 3, 4, 5, 7, 6, 8, 9, 10]})))
+                              func=generate,
+                              func_args={"baz": [0, 1, 2, 3, 4, 5, 7, 6, 8, 9, 10]})))
 
     def test_generate_file_name_from_hash_with_instance(self):
         generator = Generator2()
-        self.assertEquals("generate-baz-6979983cbc.pickle",
+        self.assertEquals("Generator2-generate-baz-6979983cbc.pickle",
                           os.path.basename(generate_path(
                               func=generator.generate,
                               func_args={"baz": [0, 1, 2, 3, 4, 5, 7, 6, 8, 9, 10]})))
+
+    def test_generate_file_name_from_hash_with_instance_of_inner_class(self):
+        generator = Generator3()
+        self.assertEquals("Generator3-InnerGenerator-generate-baz-6979983cbc.pickle",
+                          os.path.basename(generate_path(
+                              func=generator.inner.generate,
+                              func_args={"baz": [0, 1, 2, 3, 4, 5, 7, 6, 8, 9, 10]})))