Skip to content

Commit

Permalink
generate_package.py: Replace touch
Browse files Browse the repository at this point in the history
This replaces the user-defined touch
function with library function Path.

Closes #2575
  • Loading branch information
kriti21 committed Jul 4, 2018
1 parent ef0d8e0 commit b51144b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
12 changes: 2 additions & 10 deletions bears/generate_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import glob
import os
import shutil
from pathlib import Path
from string import Template
import subprocess
import sys
Expand All @@ -13,15 +14,6 @@
from coalib.parsing.Globbing import glob


def touch(file_name):
"""
Creates an empty file. An existing file remains untouched.
:param file_name: Name of the file.
"""
open(file_name, 'a').close()


def create_file_from_template(template_file, output_file, substitution_dict):
"""
Creates a file from a template file, using a substitution dict.
Expand Down Expand Up @@ -55,7 +47,7 @@ def create_file_structure_for_packages(root_folder, file_to_copy, object_name):
upload_package_folder = os.path.join(
root_folder, object_name, 'coala' + object_name)
os.makedirs(upload_package_folder, exist_ok=True)
touch(os.path.join(upload_package_folder, '__init__.py'))
Path(os.path.join(upload_package_folder, '__init__.py')).touch()
shutil.copyfile(file_to_copy, os.path.join(upload_package_folder,
object_name + '.py'))

Expand Down
10 changes: 6 additions & 4 deletions tests/generate_packageTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import shutil
import sys
import unittest
from pathlib import Path
from unittest.mock import patch
from bears.generate_package import (VERSION, touch, create_file_from_template,

from bears.generate_package import (VERSION, create_file_from_template,
create_file_structure_for_packages,
perform_register, perform_upload, main,
create_upload_parser)
Expand All @@ -17,7 +19,7 @@ def setUp(self):

def test_file_doesnt_exist(self):
self.assertFalse(os.path.exists('TestFile.py'))
touch('TestFile.py')
Path('TestFile.py').touch()
self.assertTrue(os.path.exists('TestFile.py'))

def tearDown(self):
Expand Down Expand Up @@ -52,7 +54,7 @@ class CreateFileStructureForPackagesTest(unittest.TestCase):
BEAR_FILE_PATH = os.path.join('folder', 'Test', 'coalaTest', 'Test.py')

def test_structure(self):
touch('TestFile.py')
Path('TestFile.py').touch()
create_file_structure_for_packages('folder', 'TestFile.py', 'Test')
self.assertTrue(os.path.exists(self.INIT_FILE_PATH))
self.assertTrue(os.path.exists(self.BEAR_FILE_PATH))
Expand Down Expand Up @@ -147,7 +149,7 @@ def test_register(self, call_mock):
def test_no_bear_object(self):
if not os.path.exists(self.NO_BEAR_PATH):
os.makedirs(os.path.join(self.BEARS_PATH, 'BadBear'))
touch(self.NO_BEAR_PATH)
Path(self.NO_BEAR_PATH).touch()
main()
self.assertFalse(os.path.exists(os.path.join(
self.BEARS_UPLOAD_PATH, 'BadBear')))
Expand Down

0 comments on commit b51144b

Please sign in to comment.