def test_ink_renderer_render_default_delim(self):
     """Test Ink render with default delimiters"""
     template_string = FileReader(self.template_path).read_utf8()
     standard_string = FileReader(self.standard_path).read_utf8()
     template = Template(template_string)
     renderer = Renderer(template, self.key_dictionary)
     rendered_doc = renderer.render()
     self.assertEqual(rendered_doc, standard_string)
 def test_ink_renderer_render_fail_with_incorrect_delim(self):
     """Confirm that Ink renderer fails with incorrect delimiter assignment"""
     template_string = FileReader(self.template_path).read_utf8()
     standard_string = FileReader(self.standard_path).read_utf8()
     template = Template(template_string, "[[", "]]")
     renderer = Renderer(template, self.key_dictionary)
     rendered_doc = renderer.render()
     self.assertNotEqual(rendered_doc, standard_string)
示例#3
0
		def test_ink_renderer_render_new_delim(self):
			"""Test Ink render with new delimiters"""
			template_string = FileReader(self.template_path2).read_utf8()
			standard_string = FileReader(self.standard_path).read_utf8()
			template = Template(template_string, "[[", "]]", escape_regex=True) # have to escape special regex chars
			renderer = Renderer(template, self.key_dictionary)
			rendered_doc = renderer.render()
			self.assertEqual(rendered_doc, standard_string)
示例#4
0
 def test_file_gzip_ascii_readwrite(self):
     """Test gzip compression and read from compressed ascii text file in Python 2"""
     if state.py2:
         FileWriter(self.ascii_path).gzip(self.ascii_string)
         gzip_contents = FileReader(self.ascii_path + ".gz").read_gzip()
         self.assertEqual(gzip_contents, self.ascii_string)
     elif state.py3:
         FileWriter(self.ascii_path).gzip(bytes(self.ascii_string, 'utf-8'))
         gzip_contents = FileReader(self.ascii_path + ".gz").read_gzip()
         self.assertEqual(gzip_contents.decode('ascii'), self.ascii_string)
示例#5
0
 def test_file_gzip_utf8_readwrite_explicit_decode(self):
     """Test gzip compression and read from compressed unicode text file with explicit utf-8 decode"""
     if state.py2:
         FileWriter(self.unicode_path).gzip(self.unicode_string)
         gzip_contents = FileReader(self.unicode_path + ".gz").read_gzip("utf-8") # when read with explicit utf-8 decoding, strings should match
         self.assertEqual(gzip_contents, self.unicode_string)
     elif state.py3:
         FileWriter(self.unicode_path).gzip(bytes(self.unicode_string, 'utf-8'))
         gzip_contents = FileReader(self.unicode_path + ".gz").read_gzip("utf-8") # when read with explicit utf-8 decoding, strings should match
         self.assertEqual(gzip_contents, self.unicode_string)
示例#6
0
 def test_file_ascii_readwrite_string_type(self):
     FileWriter(self.ascii_path).write(self.ascii_string) # file write
     ascii_text = FileReader(self.ascii_path).read() # file read
     if state.py2:
         self.assertEqual(type(unicode("test string")), type(ascii_text)) #python 2 treats all input as unicode type
     elif state.py3:
         self.assertEqual(type(str("test string")), type(ascii_text)) #python 3 treats all input as str
 def test_ink_make_template_varlist_new_delimiter_wrong_delim(self):
     """Test new Ink template variable list property assignment when new delimiter is wrong"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(
         template_string, "[[", "]]",
         escape_regex=True)  # have to escape special regex chars
     self.assertEqual(template.varlist, set([]))
示例#8
0
 def test_file_readutf8_writeutf8_string_type(self):
     FileWriter(self.unicode_path).write_utf8(self.unicode_string)
     unicode_text = FileReader(self.unicode_path).read_utf8()
     if state.py2:
         self.assertEqual(type(unicode("test string")), type(unicode_text)) # confirm that python2 treats as unicode
     elif state.py3:
         self.assertEqual(type(str("test string")), type(unicode_text)) # confirm that python3 treats as str
 def test_ink_renderer_new_delimiters(self):
     """Test new Ink renderer assignment of new delimiters from the template"""
     template_string = FileReader(self.template_path2).read_utf8()
     template = Template(template_string, "[[", "]]")
     renderer = Renderer(template, self.key_dictionary)
     self.assertEqual(renderer.odel, "[[")
     self.assertEqual(renderer.cdel, "]]")
示例#10
0
 def test_ink_renderer_default_delimiters(self):
     """Test new Ink renderer assignment of default delimiters from the template"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(template_string)
     renderer = Renderer(template, self.key_dictionary)
     self.assertEqual(renderer.odel, "{{")
     self.assertEqual(renderer.cdel, "}}")
示例#11
0
		def test_ink_make_template_varlist_new_delimiters(self):
			"""Test new Ink template variable list property assignment with new delimiters"""
			template_string = FileReader(self.template_path2).read_utf8()
			template = Template(template_string, "[[", "]]", escape_regex=True) # have to escape special regex chars
			if state.py2:
				# pass - need to skip this for Py3.2 tests
				self.assertEqual(template.varlist, set([u'appname', u'description', u'url', u'license', u'author', u'email']))
			else:
				self.assertEqual(template.varlist, set(['appname', 'description', 'url', 'license', 'author', 'email']))
示例#12
0
		def test_ink_make_template_varlist(self):
			"""Test new Ink template variable list property assignment"""
			template_string = FileReader(self.template_path).read_utf8()
			template = Template(template_string)
			if state.py2:
				# pass - need to skip this for Py3.2 tests
			    self.assertEqual(template.varlist, set([u'appname', u'description', u'url', u'license', u'author', u'email'])) # convert to sets to ignore order
			else:
				self.assertEqual(template.varlist, set(['appname', 'description', 'url', 'license', 'author', 'email']))
示例#13
0
 def test_http_get_text_exists_request_overwrite(self):
     """Test HTTP GET request with text file write does overwrite existing file when requested to do so"""
     filepath = os.path.join('testfiles', 'testdir', 'test.txt')
     http = HTTP(
         'https://raw.github.com/chrissimpkins/six-four/master/LICENSE')
     fw = FileWriter(filepath)
     fw.write("test")
     http.get_txt_write_file(filepath, overwrite_existing=True)
     self.assertEqual(
         FileReader(filepath).read().strip(), self.http_string.strip())
示例#14
0
 def test_http_post_text_file_absent(self):
     """Test HTTP POST request text file write when the file does not exist"""
     filepath = os.path.join('testfiles', 'testdir', 'post.txt')
     if file_exists(filepath):
         os.remove(filepath)
     http = HTTP("http://httpbin.org/post")
     http_text = http.post_txt_write_file(filepath)
     fr = FileReader(filepath)
     the_text = fr.read_utf8()  #read file in
     textobj = json.loads(the_text)  #convert JSON to Py object
     self.assertEqual(
         True, http_text)  # test boolean for confirmation of data write
     self.assertEqual(textobj['url'], 'http://httpbin.org/post'
                      )  #confirm the write of subset of the text
示例#15
0
    def test_file_ascii_safewrite(self):
        """Test safe_write() to confirm does not overwrite existing file"""
        os.remove(self.ascii_path) #remove the existing text file for tests
        if os.path.exists(self.ascii_path):
            raise IOError("The ascii test file was not deleted. (test_IO.py.test_file_ascii_safewrite)")
        else:
            safe_response = FileWriter(self.ascii_path).safe_write(self.ascii_string) # attempt safe_write when no preexisting file present
            ascii_text = FileReader(self.ascii_path).read()
            self.assertEqual(ascii_text, self.ascii_string) # assert that the correct text was written
            self.assertEqual(safe_response, True) # assert that returns True when file not present and writes

            if os.path.exists(self.ascii_path):
                    self.assertEqual(FileWriter(self.ascii_path).safe_write(self.ascii_string), False) #confirm that returns False to calling function when there is a pre-existing file
            else:
                raise IOError("The ascii test file is not present (test_IO.py.test_file_ascii_safewrite)")
示例#16
0
 def test_http_get_text_absent(self):
     """Test HTTP get request for text data and write of text file"""
     filepath = os.path.join('testfiles', 'testdir', 'test.txt')
     if file_exists(filepath):
         os.remove(filepath)
     http = HTTP(
         "https://raw.github.com/chrissimpkins/six-four/master/LICENSE")
     response = http.get_txt_write_file(filepath)
     fr = FileReader(filepath)
     the_dl_text = fr.read()
     self.assertEqual(the_dl_text.strip(), self.http_string.strip()
                      )  #test that the file write is appropriate
     self.assertEqual(
         response, True
     )  # test that the response from the method is correct (True on completed file write)
示例#17
0
 def test_ink_make_template_varlist_default_delim_wrong_delim(self):
     """Test new Ink template variable list property assignment when default delimiter is incorrect"""
     template_string = FileReader(
         self.template_path2).read_utf8()  # uses the [[ & ]] delimiters
     template = Template(template_string)
     self.assertEqual(template.varlist, set([]))
示例#18
0
 def test_ink_make_template_new_delimiters_without_escape(self):
     """test new Ink template delimiter properties assignment fails without proper regex escape"""
     template_string = FileReader(self.template_path).read_utf8()
     self.assertRaises(TypeError, Template(template_string, "[[", "]]"))
示例#19
0
 def test_ink_make_template_string(self):
     """Test new Ink template string assignment"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(template_string)
     self.assertEqual(template, template_string)
示例#20
0
 def test_ink_make_template_default_delimiter(self):
     """Test default Ink template delimiter properties assignment"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(template_string)
     self.assertEqual(template.odel, "{{")
     self.assertEqual(template.cdel, "}}")
示例#21
0
 def test_ink_make_template_new_delimiters(self):
     """Test new Ink template delimiter properties assignment"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(template_string, "[[", "]]", escape_regex=True)
     self.assertEqual(template.odel, "[[")
     self.assertEqual(template.cdel, "]]")
示例#22
0
 def test_file_ascii_readwrite_append(self):
     """Test append of ascii text to existing file"""
     FileWriter(self.ascii_path).append(self.ascii_string) #append a second string of the ascii text
     ascii_text = FileReader(self.ascii_path).read()
     self.assertEqual(ascii_text, (self.ascii_string)*2) #confirm that it equals two of the ascii strings
示例#23
0
 def test_file_ascii_readwrite(self):
     """Test write and read of ascii encoded file"""
     FileWriter(self.ascii_path).write(self.ascii_string) # file write
     ascii_text = FileReader(self.ascii_path).read() # file read
     self.assertEqual(ascii_text, self.ascii_string)
示例#24
0
 def test_ink_renderer_template_property_string(self):
     """Test new Ink renderer template property is a string"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(template_string)
     renderer = Renderer(template, self.key_dictionary)
     self.assertIsInstance(renderer.template, str)
示例#25
0
 def test_ink_renderer_key_dictionary(self):
     """Test new Ink renderer key_dict property"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(template_string)
     renderer = Renderer(template, self.key_dictionary)
     self.assertEqual(renderer.key_dict, self.key_dictionary)
示例#26
0
def generate_hash(filepath):
    """Public function that reads a local file and generates a SHA256 hash digest for it"""
    fr = FileReader(filepath)
    data = fr.read_bin()
    return _calculate_sha256(data)
示例#27
0
 def test_file_utf8_readwrite(self):
     """Test write and read of a utf-8 encoded file"""
     FileWriter(self.unicode_path).write_utf8(self.unicode_string)
     unicode_text = FileReader(self.unicode_path).read_utf8()
     self.assertEqual(unicode_text, self.unicode_string)
示例#28
0
 def test_ink_template_string_method(self):
     """Test that a slice string method works on the Ink template"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(template_string)
     self.assertEqual(template[0:5], "impor")
示例#29
0
 def test_ink_template_varlist_type_set(self):
     """Test that the Ink template variable list is of type set"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(template_string)
     self.assertIsInstance(template.varlist, set)
示例#30
0
 def test_ink_template_type_string(self):
     """Test that Ink template is of type string"""
     template_string = FileReader(self.template_path).read_utf8()
     template = Template(template_string)
     self.assertIsInstance(template, str)