def test_load_filename_string(self, prog, tmpdir): """Test loading a program using a string filename""" filename = str(tmpdir.join("test.xbb")) with open(filename, "w") as f: f.write(test_prog_not_compiled) res = sf.load(filename) # check loaded program is the same as expected self.assert_programs_equal(res, prog)
def test_load_filename_path_object(self, prog, tmpdir): """Test loading a program using a path object""" filename = tmpdir.join("test.xbb") with open(filename, "w") as f: f.write(test_blackbird_prog_not_compiled) res = sf.load(filename) # check loaded program is the same as expected self.assert_programs_equal(res, prog)
def test_load_file_object(self, prog, tmpdir): """Test loading a program via a file object""" filename = tmpdir.join("test.xbb") with open(filename, "w") as f: sf.save(f, prog) with open(filename, "r") as f: res = sf.load(f) # check loaded program is the same as expected self.assert_programs_equal(res, prog)
def test_invalid_file(self, prog, tmpdir): """Test exception is raised if file is invalid""" with pytest.raises(ValueError, match="must be a string, path"): sf.load(1)