Skip to content

Commit dd4a5e2

Browse files
committed
Rudimentary test added
1 parent 0b1c34b commit dd4a5e2

File tree

6 files changed

+185
-0
lines changed

6 files changed

+185
-0
lines changed

tests/dog_walker/bosses.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class NatureLover: # Define a type of human being that loves nature
2+
def walk (self, dog): # The NatureLover walks the dog, really
3+
print ('\nC\'mon!') # \n means start on new line, \' means ' inside string
4+
dog.follow_me () # Just lets it escape
5+
6+
class CouchPotato: # Define a type of human being that loves couchhanging
7+
def walk (self, dog): # The CouchPotato walks the dog, well, lets it go
8+
print ('\nBugger off!') # \n means start on new line
9+
dog.escape () # Just lets it escape

tests/dog_walker/dog_walker.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import bosses
2+
import dogs
3+
4+
your_dog = dogs.Dog ('Wraff') # Instantiate dog, provide sound "Wraff" to constructor
5+
his_dog = dogs.Dog ('Howl') # Instantiate dog, provide sound "Howl" to constructor
6+
7+
you = bosses.NatureLover () # Create yourself
8+
your_friend = bosses.CouchPotato () # Create your friend
9+
10+
you.walk (your_dog) # Interface: walk dog, implementation: going out together
11+
your_friend.walk (his_dog) # Interface: walk dog, implementation: sending dog out

tests/dog_walker/dogs.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Dog: # Define the dog species
2+
def __init__ (self, sound): # Constructor, named __init__, accepts provided sound
3+
self.sound = sound # Stores accepted sound into self.sound field inside new dog
4+
5+
def _bark (self): # Define _bark method, not part of interface of dog
6+
print (self.sound) # It prints the self.sound field stored inside this dog
7+
8+
def escape (self): # Define escape method
9+
print ('Hang head') # The dog hangs his head
10+
self._bark () # It then calls upon its own _bark method
11+
self._bark () # And yet again
12+
13+
def follow_me (self): # Define escape method
14+
print ('Walk behind') # The dog walks one step behind the boss
15+
self._bark () # It then calls upon its own _bark method
16+
self._bark () # And yet again

tests/dog_walker/func_walker.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import random # One of Python's many standard modules
2+
3+
import bosses
4+
import dogs
5+
6+
# Create a list of random bosses
7+
human_beings = [ # Start a so called list comprehension
8+
random.choice ( # Pick a random class
9+
(bosses.NatureLover, bosses.CouchPotato) # out of this tuple
10+
) () # and call its constructor to instantiate an object
11+
for index in range (10) # repeatedly, while letting index run from 0 to 9
12+
] # End the list comprehension, it will hold 10 objects
13+
14+
# Let them all walk a new dog with an random sound
15+
for human_being in human_beings: # Repeat the following for every human being in the list
16+
human_being.walk ( # Call implementation of walk method for that type of human being
17+
dogs.Dog ( # Construct a dog as parameter to the walk method
18+
random.choice ( # Pick a random sound
19+
('Wraff', 'Wooff', 'Howl', 'Kaii', 'Shreek') # fom this tuple of sounds
20+
)
21+
)
22+
)

tests/dog_walker/opy_config.txt

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
'''
2+
Copyright (C) 2014 - 2017 Jacques de Hooge, Geatec Engineering, www.geatec.com
3+
4+
This program is free software.
5+
You can use, redistribute and/or modify it, but only under the terms stated in the QQuickLicence.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY, without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10+
See the QQuickLicence at www.qquick.org/licence.html for details.
11+
'''
12+
13+
14+
15+
#====================================================================================================
16+
# General options
17+
# All options have default value False
18+
#====================================================================================================
19+
20+
obfuscate_strings = True # Don't rely on this for sensitive information
21+
obfuscated_name_tail = '_opy_' # Will be added to all obfuscated names to avoid clashes with plain names
22+
plain_marker = '_opy_' # Strings or comments containing this marker will not be obfuscated
23+
pep8_comments = False # If True, only inline comments of the form <blank><blank>#<blank>
24+
# will be recognized
25+
26+
27+
28+
#====================================================================================================
29+
# Extensions of files that should be obfuscated
30+
# Typically these are files containing Python source code
31+
# Other files are just copied to the target directory
32+
#====================================================================================================
33+
34+
source_extensions = '''
35+
py
36+
pyx
37+
'''
38+
39+
40+
41+
#====================================================================================================
42+
# Extensions of files that should neither be obfuscated nor copied to the target directory
43+
# Typically these are .pyc files, which could easily be decompiled, breaking obfuscation
44+
#====================================================================================================
45+
46+
skip_extensions = '''
47+
pyc
48+
'''
49+
50+
51+
52+
#====================================================================================================
53+
# Fragments that, when occuring in the path of a file, will cause this file to be ignored
54+
# In other words, such files will neither be ofuscated nor copied
55+
# Use this to exclude complete directories from any processing by Opy
56+
# N.B. Use forward slashes rather than backslashes, also on Windows!
57+
#====================================================================================================
58+
59+
skip_path_fragments = '''
60+
/test_skip_path_fragments/ # This fragment included for test purposes only
61+
'''
62+
63+
64+
65+
#====================================================================================================
66+
# Modules in sys.path containing identifiers that should not be obfuscated
67+
# Typically these are installed standard or 3rd party modules of which you have no source code
68+
# Use dotted names if needed, e.g. include both matplotlib and matplotlib.pyplot
69+
#====================================================================================================
70+
71+
external_modules = '''
72+
re
73+
os
74+
sys
75+
errno
76+
keyword
77+
importlib
78+
random
79+
codecs
80+
shutil
81+
'''
82+
83+
84+
85+
#====================================================================================================
86+
# Relative path + name of Python source files containing identifiers that should not be obfuscated
87+
# Typically these are human readable settings files loaded and exec'ed at runtime by your program
88+
# Do not use this facility for files that are imported, that's what external_modules is for
89+
#====================================================================================================
90+
91+
plain_files = '''
92+
opy_config.txt
93+
'''
94+
95+
96+
97+
#====================================================================================================
98+
# Extra identifiers and module names (as opposed to contents) that should not be obfuscated
99+
# Probably at least the names of your main modules (so not their filenames) go here
100+
#====================================================================================================
101+
102+
plain_names = '''
103+
opy
104+
currentModule
105+
dog_walker
106+
'''

tests/dog_walker/poly_walker.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import random # One of Python's many standard modules
2+
3+
import bosses
4+
import dogs
5+
6+
# Create a list of random bosses
7+
humanBeings = [] # Create an emptpy list
8+
for index in range (10): # Repeat the following 10 times, index running from 0 to 9
9+
humanBeings.append ( # Append a random HumanBeing to the list by
10+
random.choice ((bosses.NatureLover, bosses.CouchPotato)) () # randomly selecting its class
11+
) # and calling its contructor
12+
13+
# Let them all walk a new dog with an random sound
14+
for humanBeing in humanBeings: # Repeat the following for every humanBeing in the list
15+
humanBeing.walk ( # Call implementation of walk method for that type of humanBeing
16+
dogs.Dog ( # Construct a new dog as parameter to the walk method
17+
random.choice ( # Pick a random sound
18+
('Wraff', 'Wooff', 'Howl', 'Kaii', 'Shreek') # fom this tuple of sounds
19+
)
20+
)
21+
)

0 commit comments

Comments
 (0)