Skip to content

Commit

Permalink
tests for find_next_seperator
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitri-schmidt committed Apr 28, 2015
1 parent 4f56f77 commit 424913c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sqlScriptBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def progress_print(self, number, maxNumber):


def property_exists(self, propertyTalkPage):
return not (propertyTalkPage.find("Creating Property talk") != -1 or propertyTalkPage == "")
return not (propertyTalkPage.find("Creating Property talk") != -1 or
propertyTalkPage == "")


def get_constraint_end_index(self, constraintPart):
Expand Down Expand Up @@ -210,7 +211,7 @@ def split_constraint_block(self, constraint_part):
'classes' : add_classes,
'exceptions' : add_exceptions,
'group by' : add_group_by,
'group property' : add_items,
'group property' : add_group_by,
'item' : add_items,
'items' : add_items,
'list' : add_list,
Expand Down Expand Up @@ -276,7 +277,7 @@ def process_constraint_part(self, constraint_part, property_number):

def get_property_talk_page(self, property_number):
url = "http://www.wikidata.org/w/index.php?title=Property_talk:P" + \
str(property_number) + "&action=edit"
str(property_number) + "&action=edit"
property_talk_page = requests.get(url).text
return property_talk_page

Expand Down
35 changes: 35 additions & 0 deletions test_sqlScriptBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,41 @@ def setup_method(self, method):
self.builder = sqlScriptBuilder()


def test_find_next_seperator_pipe_before_next_equal(self):
test_constraint_parameters = "classes=Q1048835,Q56061|relation=instance"
test_equal_sign = 7
expected_result = 24
result = self.builder.find_next_seperator(test_constraint_parameters, test_equal_sign)
assert result == expected_result

def test_find_next_seperator_none(self):
test_constraint_parameters = "relation=instance"
test_equal_sign = 8
expected_result = 18
result = self.builder.find_next_seperator(test_constraint_parameters, test_equal_sign)
assert result == expected_result

def test_find_next_seperator_no_pipe(self):
test_constraint_parameters = "classes=Q5,Q95074 relation=instance"
test_equal_sign = 7
expected_result = 35
result = self.builder.find_next_seperator(test_constraint_parameters, test_equal_sign)
assert result == expected_result

def test_find_next_seperator_multiple_pipes(self):
test_constraint_parameters = "items={{Q|6581072}}, {{Q|43445}}|mandatory=true"
test_equal_sign = 5
expected_result = 33
result = self.builder.find_next_seperator(test_constraint_parameters, test_equal_sign)
assert result == expected_result

def test_find_next_seperator_empty_parameters(self):
test_constraint_parameters = ""
test_equal_sign = 0
expected_result = 1
result = self.builder.find_next_seperator(test_constraint_parameters, test_equal_sign)
assert result == expected_result

def test_to_comma_seperated_string_standard(self):
test_string = "{{Q|6581072}}, {{Q|43445}}, {{Q|1052281}}"
expected_result = "Q6581072,Q43445,Q1052281"
Expand Down

0 comments on commit 424913c

Please sign in to comment.