2 # -*- coding: utf-8 -*-
4 # Project ___| | | | _ \| |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at https://curl.haxx.se/docs/copyright.html.
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
22 """Module for extracting test data from the test data folder"""
24 from __future__ import (absolute_import, division, print_function,
30 log = logging.getLogger(__name__)
33 REPLY_DATA = re.compile("<reply>\s*<data>(.*?)</data>", re.MULTILINE | re.DOTALL)
36 class TestData(object):
37 def __init__(self, data_folder):
38 self.data_folder = data_folder
40 def get_test_data(self, test_number):
41 # Create the test file name
42 filename = os.path.join(self.data_folder,
43 "test{0}".format(test_number))
45 log.debug("Parsing file %s", filename)
47 with open(filename, "rb") as f:
48 contents = f.read().decode("utf-8")
50 m = REPLY_DATA.search(contents)
52 raise Exception("Couldn't find a <reply><data> section")
54 # Left-strip the data so we don't get a newline before our data.
55 return m.group(1).lstrip()
58 if __name__ == '__main__':
59 td = TestData("./data")
60 data = td.get_test_data(1)