Skip to content

Commit

Permalink
mocks: support package definition
Browse files Browse the repository at this point in the history
  • Loading branch information
jpochyla committed Oct 10, 2018
1 parent b3f1017 commit 7c07752
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tools/build_mocks
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def split_to_parts(line, mod_desc=None):
global current_indent
global current_class
global current_method
global current_package

if line.startswith("package: "):
current_package = line[9:].strip()
return

if line.startswith("class "):
current_class = line[6:].split("(")[0].strip(":")
Expand All @@ -38,15 +43,16 @@ def split_to_parts(line, mod_desc=None):

def store_to_file(dest, parts):
for package, line in parts:
dirpath = os.path.abspath(dest)
filename = package
package = package.replace(".", "/")
dirpath = os.path.join(os.path.abspath(dest), os.path.dirname(package))
filename = os.path.basename(package) + ".py"

if not os.path.exists(dirpath):
os.makedirs(dirpath)
open(os.path.join(dirpath, "__init__.py"), "w").close()
open(os.path.join(dirpath, ".mock-generated"), "w").close()

filepath = os.path.join(dirpath, filename + ".py")
filepath = os.path.join(dirpath, filename)

if not os.path.exists(filepath):
with open(filepath, "a") as f:
Expand Down Expand Up @@ -83,7 +89,9 @@ def build_module(mod_file, dest):

def build_directory(dir, dest):
print("Building mocks for", dir, "to", dest)
for pkg in sorted([x for x in os.listdir(dir) if os.path.isdir(os.path.join(dir, x))]):
for pkg in sorted(
[x for x in os.listdir(dir) if os.path.isdir(os.path.join(dir, x))]
):
for mod in sorted(os.listdir(os.path.join(dir, pkg))):
build_module(os.path.join(dir, pkg, mod), dest)

Expand Down

0 comments on commit 7c07752

Please sign in to comment.