def write_pys_out(self, method_name, *args, **kwargs): """Helper that writes an pys_out file""" outfile = bz2.BZ2File(self.pys_outfile_path, "w") pys_out = Pys(self.code_array, outfile) method = getattr(pys_out, method_name) method(*args, **kwargs) outfile.close()
def setup_method(self, method): """Creates Pys class with code_array and temporary test.pys file""" # All data structures are initially empty # The test file pys_file has entries in each category self.code_array = CodeArray((1000, 100, 3)) self.pys_infile = bz2.BZ2File(TESTPATH + "pys_test1.pys") self.pys_outfile_path = TESTPATH + "pys_test2.pys" self.pys_in = Pys(self.code_array, self.pys_infile)
def test_from_code_array(self): """Test from_code_array method""" self.pys_infile.seek(0) self.pys_in.to_code_array() outfile = bz2.BZ2File(self.pys_outfile_path, "w") pys_out = Pys(self.code_array, outfile) pys_out.from_code_array() outfile.close() self.pys_infile.seek(0) in_data = self.pys_infile.read() outfile = bz2.BZ2File(self.pys_outfile_path) out_data = outfile.read() outfile.close() # Clean up the test dir os.remove(self.pys_outfile_path) assert in_data == out_data