Skip to content

Commit 17c0dca

Browse files
committed
Change naming of challenge class filename
Change the pathname pattern from: MyChallenge/MyChallenge.py MyChallenge/MyChallengeTestCase.py to: MyChallenge/challenge.py MyChallenge/testcase.py The old convention led to minor issues with library resolution. The new convention works much better with IDE. Implement this in name resolution, scaffolding and documentation.
1 parent 55f7437 commit 17c0dca

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed
File renamed without changes.

HelloWorld/HelloWorldTestCase.py renamed to HelloWorld/testcase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22

3-
from .HelloWorld import HelloWorld
3+
from .challenge import HelloWorld
44

55

66
class HelloWorldTestCase(unittest.TestCase):

README.rst

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ The Layout of Your Directory Looks Like This
7070
.. code-block:: bash
7171
7272
myChallenges/
73-
Challenge1/Challenge1.py
74-
Challenge1/Challenge1TestCase.py
75-
Challenge2/Challenge2.py
76-
Challenge2/Challenge2TestCase.py
73+
Challenge1/challenge.py
74+
Challenge1/testcase.py
75+
Challenge2/challenge.py
76+
Challenge2/testcase.py
7777
... more challenges ...
7878
7979
The names `Challenge1` and `Challenge2` are just placeholders for the names you choose during scaffolding.
@@ -107,8 +107,9 @@ You now find the files:
107107
.. code-block:: bash
108108
109109
myChallenges/
110-
Challenge3/Challenge3.py
111-
Challenge3/Challenge3TestCase.py
110+
Challenge3/challenge.py
111+
Challenge3/testcase.py
112+
Challenge3/__init__.py
112113
113114
Check it's working by running the unit test case.
114115

@@ -190,28 +191,38 @@ There are two deliberate exceptions:
190191

191192
1. Challenge module names are **CamelCase**:
192193

193-
In contradiction to the style guide directory and class file of the challenges are not all lowercase. Especially the
194+
In contradiction to the style guide directories of the challenges are not all lowercase. Especially the
194195
first character must be uppercase. This is used to find and list the challenge directories between other modules.
195-
Even more, the directory, the class file and the class name must all use the same word, with the `.py` extension for
196-
the file.
196+
The directory and the class name must use the same word, with the `.py` extension for the file.
197197

198198
2. Inherited class attributes and methods don't have a leading underscore:
199199

200200
The inherited functions and methods of the challenge are not a public API and the style guides recommends leading
201201
underscores. As inheritance is a core concept of the challenge class, this would lead to a hell of leading
202202
underscores. For this reason we don't follow the style guide in this recommendation.
203203

204+
.. tip::
205+
206+
On useful advantage of naming the directory just like your challenge class is, that you can use the path expansion
207+
mechanism of the shell. Write the first characters of the class/directory name and hit <TAB>. Now you can use the
208+
directory name as name of the challenge. A trailing slash is discarded. The following two inputs are equivalent.
209+
210+
.. code-block:: bash
211+
212+
prompt> challenge -k HelloWorld
213+
prompt> challenge -k HelloWorld/
214+
204215
Installation
205216
============
206217

207218
.. important::
208219

209-
This solftware requieres Python 3.
220+
This software requires Python 3.
210221

211222
Clone from Github
212223
-----------------
213224

214-
You can clone (or download) the Challenges project directly from Github. In this case the scripts and pathes are not
225+
You can clone (or download) the Challenges project directly from Github. In this case the scripts and paths are not
215226
configured globally. Either you configure it globally or you place your challenges immediately into the projects folder
216227
so that the paths are detected relatively.
217228

challenges/conf.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def parse_arguments(self):
4242
if len(sys.argv) == 1:
4343
self.print_help()
4444
self.args = self.parser.parse_args()
45+
if self.args.challenge[-1:] == '/':
46+
self.args.challenge = self.args.challenge[0:-1]
4547

4648
def print_help(self):
4749
self.parser.print_help()
@@ -52,11 +54,11 @@ def get_challenge_dir(self):
5254

5355
def get_challenge_file(self):
5456
challenge = self.args.challenge
55-
return self.root + '/' + challenge + '/' + challenge + '.py'
57+
return self.root + '/' + challenge + '/challenge.py'
5658

5759
def get_unittest_file(self):
5860
challenge = self.args.challenge
59-
return self.root + '/' + challenge + '/' + challenge + 'TestCase.py'
61+
return self.root + '/' + challenge + '/testcase.py'
6062

6163
def get_input_file(self):
6264
return os.path.realpath(self.args.file)
@@ -85,12 +87,11 @@ def get_challenge_class(self):
8587

8688
def get_full_qualified_challenge_class(self):
8789
challenge = self.args.challenge
88-
return challenge + '.' + challenge + '.' + challenge
90+
return challenge + '.challenge.' + challenge
8991

9092
def get_full_qualified_unittest_class(self):
9193
challenge = self.args.challenge
92-
return (challenge + '.' + challenge + 'TestCase.' + challenge +
93-
'TestCase')
94+
return (challenge + '.testcase.' + challenge + 'TestCase')
9495

9596
def get_challenge(self):
9697
return self.get_class(self.get_full_qualified_challenge_class())()

challenges/scaffold.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ def calc(self):
5353
def get_unittest_content(self):
5454
text = '''
5555
import unittest
56-
from {}.{} import {}
56+
from {}.challenge import {}
5757
5858
class {}TestCase(unittest.TestCase):
5959
6060
def setUp(self):
6161
self.challenge = {}()
62+
self.challenge.read()
6263
6364
def test__init__(self):
6465
self.assertIsInstance(self.challenge, {})
6566
6667
'''
6768
c = self.conf.get_challenge_class()
68-
return text.strip().format(c, c, c, c, c, c)
69+
return text.strip().format(c, c, c, c, c)

0 commit comments

Comments
 (0)