Skip to content

Commit

Permalink
Support for many_data_sources builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-verma committed Mar 2, 2020
1 parent a23ee68 commit 90ae1ae
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELIST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Following is the list of critical additions and updates for a given released ver
- Support for `data_class` markup.
- Support for `data_file` markup (Out of the box support for XLS, TSV/CSV and INI formats.)
- Support for record filtering in data files.
- Support for `many_data_sources` builder.
- Added example code and docs for data driven testing.

0.9.3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'''
This file is a part of Arjuna
Copyright 2015-2020 Rahul Verma
Website: www.RahulVerma.net
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''

from arjuna import *

class MyDataClass:

def __iter__(self):
records = (
{'left':10, 'right':12, 'sum':22},
{'left':20, 'right':32, 'sum':13},
)
return iter(records)


def myrange():
return (
{'left':30, 'right':42, 'sum':72},
{'left':40, 'right':52, 'sum':17},
)

@test(drive_with=many_data_sources(
record(left=1, right=2, sum=3),
records(
record(left=3, right=4, sum=7),
record(left=7, right=8, sum=10)
),
data_function(myrange),
data_class(MyDataClass),
data_file("input.xls")
))
def check_drive_with_many_sources(request, data):
request.asserter.assert_equal(int(data.left) + int(data.right), int(data.sum), "Calculation failed.")
3 changes: 3 additions & 0 deletions arjuna/engine/data/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ def __init_next_source(self):
except:
raise StopIteration()

def reset(self):
self.def_iter = iter(self.dsdefs)

def get_next(self):
if self.current_dsource is None:
self.__init_next_source()
Expand Down
41 changes: 41 additions & 0 deletions docs/core/DataDrivenTesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,46 @@ Sum = 3
3. For delimiter-separated-files, you can also comment a record by putting a `#` at the beginning.
4. For INI files, you can also comment a complete record by using `;` which is the commenting symbol for INI files.

#### Multiple Data Sources

You can also associate multiple data sources with a single test in Arjuna.

```python
# arjuna-samples/arjex_core_features/test/module/check_12_dd_many_data_sources.py

from arjuna import *

class MyDataClass:

def __iter__(self):
records = (
{'left':10, 'right':12, 'sum':22},
{'left':20, 'right':32, 'sum':13},
)
return iter(records)


def myrange():
return (
{'left':30, 'right':42, 'sum':72},
{'left':40, 'right':52, 'sum':17},
)

@test(drive_with=many_data_sources(
record(left=1, right=2, sum=3),
records(
record(left=3, right=4, sum=7),
record(left=7, right=8, sum=10)
),
data_function(myrange),
data_class(MyDataClass),
data_file("input.xls")
))
def check_drive_with_many_sources(request, data):
request.asserter.assert_equal(int(data.left) + int(data.right), int(data.sum), "Calculation failed.")
```

##### Points to Note
1. We can provide multiple data sources using the `many_data_sources` builder function.
2. Rest of the code remains same. This test will run for a total of `9 times` based on data records from all the sources.

0 comments on commit 90ae1ae

Please sign in to comment.