Skip to content

Commit

Permalink
Improve+test cath-ssap's handling of readonly dir
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyelewis committed Nov 28, 2017
1 parent dd745b1 commit a144940
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
4 changes: 2 additions & 2 deletions source/src_common/common/file/open_fstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ namespace cath {
+ r_or_w_str
+ " ["
+ ex.what()
+ "] "
+ "] : "
+ std::strerror( errno )
);
perror(error_message.c_str());
BOOST_THROW_EXCEPTION(cath::common::runtime_error_exception(error_message));
};

Expand Down
22 changes: 21 additions & 1 deletion source/uni/alignment/io/alignment_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ using boost::algorithm::starts_with;
using boost::algorithm::trim_copy;
using boost::empty_formatter;
using boost::filesystem::path;
using boost::filesystem::temp_directory_path;
using boost::format;
using boost::is_alpha;
using boost::is_print;
Expand Down Expand Up @@ -828,7 +829,26 @@ void cath::align::write_alignment_as_cath_ssap_legacy_format(const path
const region_vec_opt &arg_regions_b ///< TODOCUMENT
) {
ofstream aln_out_stream;
open_ofstream( aln_out_stream, arg_output_file );
try {
open_ofstream( aln_out_stream, arg_output_file );
}
catch (const runtime_error_exception &ex) {
const path alt_output_path = temp_directory_path() / arg_output_file.filename();
if ( alt_output_path == arg_output_file ) {
throw;
}
BOOST_LOG_TRIVIAL( warning )
<< "Was unable to write alignment to arg_output_file ("
<< ex.what()
<< ") - will try writing to "
<< alt_output_path
<< " instead";
if ( aln_out_stream.is_open() ) {
aln_out_stream.close();
}
aln_out_stream.clear();
open_ofstream( aln_out_stream, alt_output_path );
}

// Try here to catch any I/O exceptions
try {
Expand Down
25 changes: 23 additions & 2 deletions source/uni/alignment/io/alignment_io_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "alignment/io/alignment_io.hpp"
#include "chopping/region/region.hpp"
#include "common/boost_addenda/log/log_to_ostream_guard.hpp"
#include "common/file/open_fstream.hpp"
#include "common/pair_insertion_operator.hpp"
#include "file/pdb/pdb.hpp"
Expand All @@ -34,18 +35,24 @@
#include "structure/protein/sec_struc.hpp"
#include "structure/protein/sec_struc_planar_angles.hpp"
#include "test/boost_addenda/boost_check_equal_ranges.hpp"
#include "test/boost_addenda/boost_check_no_throw_diag.hpp"
#include "test/global_test_constants.hpp"
#include "test/predicate/istreams_equal.hpp"

#include <fstream>
#include <iostream>

namespace cath { namespace test { } }

using namespace cath;
using namespace cath::align;
using namespace cath::common;
using namespace cath::file;
using namespace cath::test;
using namespace std;

using boost::filesystem::path;

//namespace std {
// /// \brief Naughty addition of an insertion operator into std:: to get Boost.Test to output str_str_pairs
// ostream & operator<<(ostream &arg_os, ///< ostream to which to output the str_str_pair
Expand Down Expand Up @@ -87,7 +94,7 @@ namespace cath {
} // namespace test
} // namespace cath

BOOST_FIXTURE_TEST_SUITE(alignment_io_test_suite, cath::test::alignment_io_test_suite_fixture)
BOOST_FIXTURE_TEST_SUITE(alignment_io_test_suite, alignment_io_test_suite_fixture)

/// \brief A sub test-suite for testing FASTA parsing
BOOST_AUTO_TEST_SUITE(fasta_test_suite)
Expand Down Expand Up @@ -153,6 +160,21 @@ BOOST_AUTO_TEST_CASE(throws_if_sequence_line_contains_non_dash_or_letter_chars)

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_CASE(writing_aln_ssap_legacy_file_to_slash_does_not_fail) {
alignment the_alignment{ 2 };
the_alignment.set_scores( make_alignment_residue_scores( the_alignment, { score_opt_vec{}, score_opt_vec{} } ) );

ostringstream test_ss;
const log_to_ostream_guard parse_log_guard{ test_ss };

BOOST_CHECK_NO_THROW_DIAG( write_alignment_as_cath_ssap_legacy_format(
"/cath-tools-ssap-legacy-file-in-slash-test",
the_alignment,
protein(),
protein()
) );
}

/// \brief TODOCUMENT
BOOST_AUTO_TEST_CASE(alignment_legacy_input_output) {
ostringstream err_ss;
Expand Down Expand Up @@ -184,7 +206,6 @@ BOOST_AUTO_TEST_CASE(alignment_legacy_input_output) {
// Check that the data in the read+written alignment matches the original
BOOST_CHECK_EQUAL( expected_ss.str(), got_ss.str() );
BOOST_CHECK_EQUAL( err_ss.str(), ""s );

}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit a144940

Please sign in to comment.