Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nutti committed Oct 1, 2023
1 parent 6ff12e2 commit 6360d39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
18 changes: 11 additions & 7 deletions src/fake_bpy_module/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,11 @@ def build_child_modules(
structure: 'ModuleStructure', module_level: int):
for m in structure.children():
mod_name = name + m.name
if len(m.children()) == 0 and module_level != 0:
filename = re.sub(r"\.", "/", mod_name) + ".py"
if len(m.children()) == 0:
if module_level != 0:
filename = re.sub(r"\.", "/", mod_name) + ".py"
else:
filename = re.sub(r"\.", "/", mod_name) + "/__init__.py"
info = gen_info.create_target(filename)
info.data = []
info.child_modules = []
Expand Down Expand Up @@ -1224,11 +1227,12 @@ def make_module_dirs(base_path: str, structure: 'ModuleStructure'):
def make_dir(path, structure_: 'ModuleStructure',
module_level: int):
for item in structure_.children():
if len(item.children()) == 0 and module_level != 0:
dir_path = path + "/" + item.name
pathlib.Path(dir_path).mkdir(
parents=True, exist_ok=True)
self._create_py_typed_file(dir_path)
if len(item.children()) == 0:
if module_level != 0:
dir_path = path + "/" + item.name
pathlib.Path(dir_path).mkdir(
parents=True, exist_ok=True)
self._create_py_typed_file(dir_path)
elif len(item.children()) >= 1:
dir_path = path + "/" + item.name
pathlib.Path(dir_path).mkdir(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,9 @@ def test_single_rule(self):
self.assertIsNotNone(actual_rule)
self.assertIsNotNone(actual_gen_info)

self.assertEqual(set(actual_gen_info.targets()), {"module_abc.py"})
self.assertEqual(set(actual_gen_info.targets()), {"module_abc/__init__.py"})

target_module_abc = actual_gen_info.get_target("module_abc.py")
target_module_abc = actual_gen_info.get_target("module_abc/__init__.py")
self.assertEqual(len(target_module_abc.data), 1)
self.assertEqual(target_module_abc.data[0].type(), "class")
self.assertEqual(target_module_abc.data[0].name(), "Class123")
Expand Down Expand Up @@ -726,7 +726,7 @@ def test_multiple_rules(self):
self.assertEqual(
set(actual_gen_info_1.targets()),
{"module_1/__init__.py", "module_1/submodule_1.py"})
self.assertEqual(set(actual_gen_info_2.targets()), {"module_2.py"})
self.assertEqual(set(actual_gen_info_2.targets()), {"module_2/__init__.py"})

target_module_1 = actual_gen_info_1.get_target("module_1/__init__.py")
self.assertEqual(len(target_module_1.data), 1)
Expand Down Expand Up @@ -755,7 +755,7 @@ def test_multiple_rules(self):
self.assertEqual(len(target_module_1_submodule_1.child_modules), 0)
self.assertEqual(len(target_module_1_submodule_1.dependencies), 0)

target_module_2 = actual_gen_info_2.get_target("module_2.py")
target_module_2 = actual_gen_info_2.get_target("module_2/__init__.py")
self.assertEqual(len(target_module_2.data), 1)
self.assertEqual(target_module_2.data[0].type(), "function")
self.assertEqual(target_module_2.data[0].name(), "function_1")
Expand Down Expand Up @@ -822,9 +822,9 @@ def test_exceptional_rule(self):
self.assertIsNotNone(actual_gen_info)

self.assertEqual(
set(actual_gen_info.targets()), {"module_exceptional.py"})
set(actual_gen_info.targets()), {"module_exceptional/__init__.py"})

target_module_abc = actual_gen_info.get_target("module_exceptional.py")
target_module_abc = actual_gen_info.get_target("module_exceptional/__init__.py")
self.assertEqual(len(target_module_abc.data), 2)
self.assertEqual(target_module_abc.data[0].type(), "class")
self.assertEqual(target_module_abc.data[0].name(), "ClassExp")
Expand Down

0 comments on commit 6360d39

Please sign in to comment.