Skip to content

Commit

Permalink
Stub Impl on existing file should not create new file, getgauge/gauge…
Browse files Browse the repository at this point in the history
  • Loading branch information
riju91 committed Mar 27, 2018
1 parent f3d22c4 commit 039b28b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions getgauge/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,13 @@ def _get_stub_impl_content(request, response, socket):
response.messageType = Message.FileDiff
file_name = request.stubImplementationCodeRequest.implementationFilePath
codes = request.stubImplementationCodeRequest.codes
content = read_file_contents(file_name).replace('\r\n', '\n')
if len(content) > 0:
content = read_file_contents(file_name)
if content is not None:
new_line_char = '\n' if len(content.strip().split('\n')) == len(content.split('\n')) else ''
codes.insert(0, new_line_char)
lastLine = len(content.split('\n'))
span = Span(**{'start': lastLine, 'startChar': 0, 'end': lastLine, 'endChar': 0})
last_line = len(content.split('\n'))
prefix = "from getgauge.python import step\n" if len(content) == 0 else new_line_char
codes.insert(0, prefix)
span = Span(**{'start': last_line, 'startChar': 0, 'end': last_line, 'endChar': 0})
else:
file_name = get_file_name()
codes.insert(0, "from getgauge.python import step\n")
Expand Down
4 changes: 2 additions & 2 deletions getgauge/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def get_impl_files():
def read_file_contents(file_name):
if os.path.isfile(file_name):
f = open(file_name)
content = f.read()
content = f.read().replace('\r\n', '\n')
f.close()
return content
return ""
return None


def get_file_name(prefix='', counter=0):
Expand Down

0 comments on commit 039b28b

Please sign in to comment.