Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tdd #217

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Tdd #217

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
114 changes: 114 additions & 0 deletions .vscode/.ropeproject/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# The default ``config.py``
# flake8: noqa


def set_prefs(prefs):
"""This function is called before opening the project"""

# Specify which files and folders to ignore in the project.
# Changes to ignored resources are not added to the history and
# VCSs. Also they are not returned in `Project.get_files()`.
# Note that ``?`` and ``*`` match all characters but slashes.
# '*.pyc': matches 'test.pyc' and 'pkg/test.pyc'
# 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc'
# '.svn': matches 'pkg/.svn' and all of its children
# 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o'
# 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o'
prefs['ignored_resources'] = ['*.pyc', '*~', '.ropeproject',
'.hg', '.svn', '_svn', '.git', '.tox']

# Specifies which files should be considered python files. It is
# useful when you have scripts inside your project. Only files
# ending with ``.py`` are considered to be python files by
# default.
# prefs['python_files'] = ['*.py']

# Custom source folders: By default rope searches the project
# for finding source folders (folders that should be searched
# for finding modules). You can add paths to that list. Note
# that rope guesses project source folders correctly most of the
# time; use this if you have any problems.
# The folders should be relative to project root and use '/' for
# separating folders regardless of the platform rope is running on.
# 'src/my_source_folder' for instance.
# prefs.add('source_folders', 'src')

# You can extend python path for looking up modules
# prefs.add('python_path', '~/python/')

# Should rope save object information or not.
prefs['save_objectdb'] = True
prefs['compress_objectdb'] = False

# If `True`, rope analyzes each module when it is being saved.
prefs['automatic_soa'] = True
# The depth of calls to follow in static object analysis
prefs['soa_followed_calls'] = 0

# If `False` when running modules or unit tests "dynamic object
# analysis" is turned off. This makes them much faster.
prefs['perform_doa'] = True

# Rope can check the validity of its object DB when running.
prefs['validate_objectdb'] = True

# How many undos to hold?
prefs['max_history_items'] = 32

# Shows whether to save history across sessions.
prefs['save_history'] = True
prefs['compress_history'] = False

# Set the number spaces used for indenting. According to
# :PEP:`8`, it is best to use 4 spaces. Since most of rope's
# unit-tests use 4 spaces it is more reliable, too.
prefs['indent_size'] = 4

# Builtin and c-extension modules that are allowed to be imported
# and inspected by rope.
prefs['extension_modules'] = []

# Add all standard c-extensions to extension_modules list.
prefs['import_dynload_stdmods'] = True

# If `True` modules with syntax errors are considered to be empty.
# The default value is `False`; When `False` syntax errors raise
# `rope.base.exceptions.ModuleSyntaxError` exception.
prefs['ignore_syntax_errors'] = False

# If `True`, rope ignores unresolvable imports. Otherwise, they
# appear in the importing namespace.
prefs['ignore_bad_imports'] = False

# If `True`, rope will insert new module imports as
# `from <package> import <module>` by default.
prefs['prefer_module_from_imports'] = False

# If `True`, rope will transform a comma list of imports into
# multiple separate import statements when organizing
# imports.
prefs['split_imports'] = False

# If `True`, rope will remove all top-level import statements and
# reinsert them at the top of the module when making changes.
prefs['pull_imports_to_top'] = True

# If `True`, rope will sort imports alphabetically by module name instead
# of alphabetically by import statement, with from imports after normal
# imports.
prefs['sort_imports_alphabetically'] = False

# Location of implementation of
# rope.base.oi.type_hinting.interfaces.ITypeHintingFactory In general
# case, you don't have to change this value, unless you're an rope expert.
# Change this value to inject you own implementations of interfaces
# listed in module rope.base.oi.type_hinting.providers.interfaces
# For example, you can add you own providers for Django Models, or disable
# the search type-hinting in a class hierarchy, etc.
prefs['type_hinting_factory'] = (
'rope.base.oi.type_hinting.factory.default_type_hinting_factory')


def project_opened(project):
"""This function is called after opening the project"""
# Do whatever you like here!
Binary file added .vscode/.ropeproject/objectdb
Binary file not shown.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"restructuredtext.confPath": "${workspaceFolder}"
}
40 changes: 40 additions & 0 deletions create-with-arg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sys,os

print(sys.argv)


def main():
l = sys.argv[1].split("/")
alist = [
[
l[-1].upper(),
l[-1],
','+sys.argv[2] if len(sys.argv)>=3 else ''
]
]
dirName = '/'.join(l[:-1])
# Create target directory & all intermediate directories if don't exists
try:
print("Directory " , dirName , " Created ")
os.makedirs(dirName)
except FileExistsError:
print("Directory " , dirName , " already exists")
for item in alist:
f = open(sys.argv[1] + ".py", "w+")
# for i in range(10):
# f.write("This is line %d\r\n" % (i+1))
content = """
import unittest{2}
class TDD_{0}(unittest.TestCase):
def test_{1}(self):

if __name__ == '__main__':
unittest.main()

"""
f.write(content.format(item[0], item[1],item[2]))
f.close()


if __name__ == "__main__":
main()
25 changes: 25 additions & 0 deletions func2.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
myfunc2 was called
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
myfunc2
37 changes: 37 additions & 0 deletions out.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
myfunc1 was called
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
myfunc1
17 changes: 17 additions & 0 deletions out2.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
myfunc1 was called
1 change: 1 addition & 0 deletions some_file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hola!
83 changes: 83 additions & 0 deletions test/Classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import unittest
class TDD_CLASSES(unittest.TestCase):
def test_Classes(self):
class Cal(object):
# pi is a class variable
pi = 3.142
def __init__(self, radius):
# self.radius is an instance variable
self.radius = radius
def area(self):
return self.pi * (self.radius ** 2)
a = Cal(32)
self.assertEqual(a.area(),Cal.pi*a.radius**2)
self.assertEqual(a.pi,3.142)
a.pi = 43
self.assertEqual(a.pi,43)
b = Cal(44)
self.assertEqual(b.area(),3.142*44**2)
self.assertEqual(b.pi,3.142)
b.pi = 50
self.assertEqual(b.pi,50)
def test_mutable_class_var(self):
class SuperClass(object):
superpowers = []
def __init__(self, name):
self.name = name
def add_superpower(self, power):
self.superpowers.append(power)
foo = SuperClass('foo')
bar = SuperClass('bar')
self.assertEqual(foo.name,'foo')
self.assertEqual(bar.name,'bar')
self.assertEqual(bar.superpowers,[])
foo.add_superpower('fly')
self.assertEqual(bar.superpowers,['fly'])
self.assertEqual(bar.superpowers,foo.superpowers)
def test_new_style_class(self):
class OldClass():
def __init__(self):
pass
class NewClass(object):
def __init__(self):
pass
old = OldClass()
new = NewClass()
self.assertIsInstance(old,object)
self.assertIsInstance(new,object)
def test_magic_methods(self):
class GetTest(object):
def __init__(self,i=0):
self.i=i+1
def another_method(self):
self.i+=1
a = GetTest()
self.assertEqual(a.i,1)
a.another_method()
self.assertEqual(a.i,2)
class GetTest(object):
def __init__(self, name):
self.greet=('Greetings!! {0}'.format(name))
def another_method(self):
print('I am another method which is not'
' automatically called')
a = GetTest('yasoob')
self.assertEqual(a.greet,'Greetings!! yasoob')
# Try creating an instance without the name arguments
self.assertRaises(TypeError, lambda: GetTest())
self.assertRaises(TypeError,lambda:a['name'])
def test_getitem(self):
class GetTest(object):
def __init__(self):
self.info = {
'name':'Yasoob',
'country':'Pakistan',
'number':12345812
}
def __getitem__(self,i):
return self.info[i]
foo = GetTest()
self.assertEqual(foo['name'],'Yasoob')
self.assertEqual(foo['number'],12345812)
if __name__ == '__main__':
unittest.main()
30 changes: 30 additions & 0 deletions test/Coroutines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

import unittest
class TDD_COROUTINES(unittest.TestCase):
def test_Coroutines(self):
def fib(n):
a, b = 0, 1
while a<n:
yield a
a, b = b, a + b
l=[]
for i in fib(10):
l.append(i)
self.assertEqual(l,[0,1,1,2,3,5,8])
def grep(pattern):
self.assertEqual( pattern,'coroutine')
while True:
line = (yield)
if pattern in line:
print(line)
search = grep('coroutine')
next(search)
# # Output: Searching for coroutine
search.send("I love you")
search.send("Don't you love me?")
search.send("I love coroutines instead!")
search.close()
if __name__ == '__main__':
unittest.main()


15 changes: 15 additions & 0 deletions test/Enumerate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import unittest
class TDD_ENUMERATE(unittest.TestCase):
def test_Enumerate(self):
my_list = ['apple', 'banana', 'grapes', 'pear']
d={}
for counter, value in enumerate(my_list):
d[counter] = value
self.assertEqual(d,{0: 'apple', 1: 'banana', 2: 'grapes', 3: 'pear'})
counter_list = list(enumerate(my_list, 1))
self.assertEqual(counter_list,[(1, 'apple'), (2, 'banana'), (3, 'grapes'), (4, 'pear')])
if __name__ == '__main__':
unittest.main()


Loading