Skip to content

Commit

Permalink
#21 Unit test upd. #26.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolay-r committed Apr 17, 2022
1 parent 210e8a9 commit bb25561
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/demo/wui.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def prepare_template(data, text, bratUrl):
text = inputData.getfirst("text")

if not text:
template = prepare_template(data={}, text="США вводит сакнции против РФ", bratUrl=bratUrl)
template = prepare_template(data={}, text="США вводит санкции против РФ", bratUrl=bratUrl)
cgi_output(template)
exit(0)

Expand Down
13 changes: 9 additions & 4 deletions test/test_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@
class TestDemo(unittest.TestCase):

current_dir = dirname(realpath(__file__))
TEST_DATA_DIR = join(current_dir, "data")
ORIGIN_DATA_DIR = join(current_dir, "../data")

@staticmethod
def __prepare_template(data, text, template_filepath):
def __prepare_template(data, text, template_filepath, brat_url):
assert(isinstance(brat_url, str))
assert(isinstance(data, dict))

with open(template_filepath, "r") as template_file:
template_local = template_file.read()

template_local = template_local.replace("$____COL_DATA_SEM____", json.dumps(data.get('coll_data', '')))
template_local = template_local.replace("$____DOC_DATA_SEM____", json.dumps(data.get('doc_data', '')))
template_local = template_local.replace("$____BRAT_URL____", brat_url)
template_local = template_local.replace("$____TEXT____", text)

return template_local

def test_demo_rus_bert(self):
text = "США вводит сакнции против РФ"
text = "США вводит санкции против РФ"
contents = demo_infer_texts_bert(
text=text,
output_dir=".",
Expand All @@ -35,9 +38,11 @@ def test_demo_rus_bert(self):

template = TestDemo.__prepare_template(
data=contents, text=text,
template_filepath=join(TestDemo.ORIGIN_DATA_DIR, "brat_template.html"))
template_filepath=join(TestDemo.ORIGIN_DATA_DIR, "brat_template.html"),
brat_url="http://localhost:8001/")

print(template)
with open(join(self.TEST_DATA_DIR, "demo-rus-bert-output.html"), "w") as output:
output.write(template)


if __name__ == '__main__':
Expand Down

0 comments on commit bb25561

Please sign in to comment.