Пример #1
0
    def test_record_no_timestamp(self, mock_datetime):
        fake_timestamp(mock_datetime)
        self.text_output = TextOutput(self.log_file.name, with_timestamp=False)

        text = "TESTING 123 GARAGE"
        self.text_output.record(text)
        self.text_output.dump()

        with open(self.log_file.name, "r") as file:
            correct = "TESTING 123 GARAGE\n"
            assert file.read() == correct
Пример #2
0
def set_logger(log_prefix):
    current_time = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
    log_dir = "log/{}/{}/".format(log_prefix, current_time)
    text_log_file = "{}debug.log".format(log_dir)
    tabular_log_file = "{}progress.csv".format(log_dir)
    logger.add_output(TextOutput(text_log_file))
    logger.add_output(CsvOutput(tabular_log_file))
    logger.add_output(TensorBoardOutput(log_dir))
    logger.add_output(StdOutput())
Пример #3
0
 def setUp(self):
     self.log_file = tempfile.NamedTemporaryFile()
     self.text_output = TextOutput(self.log_file.name)
     self.tabular = TabularInput()
Пример #4
0
class TestTextOutput(unittest.TestCase):
    def setUp(self):
        self.log_file = tempfile.NamedTemporaryFile()
        self.text_output = TextOutput(self.log_file.name)
        self.tabular = TabularInput()

    def tearDown(self):
        self.log_file.close()

    def test_record(self, mock_datetime):
        fake_timestamp(mock_datetime)

        text = "TESTING 123 GARAGE"
        self.text_output.record(text)
        self.text_output.dump()

        with open(self.log_file.name, "r") as file:
            correct = "{} | TESTING 123 GARAGE\n".format(FAKE_TIMESTAMP_SHORT)
            assert file.read() == correct

        more_text = "MORE TESTING"
        self.text_output.record(more_text)
        self.text_output.dump()

        with open(self.log_file.name, "r") as file:
            correct = "{} | TESTING 123 GARAGE\n" "{} | MORE TESTING\n".format(
                FAKE_TIMESTAMP_SHORT, FAKE_TIMESTAMP_SHORT
            )  # yapf: disable
            assert file.read() == correct

    def test_record_no_timestamp(self, mock_datetime):
        fake_timestamp(mock_datetime)
        self.text_output = TextOutput(self.log_file.name, with_timestamp=False)

        text = "TESTING 123 GARAGE"
        self.text_output.record(text)
        self.text_output.dump()

        with open(self.log_file.name, "r") as file:
            correct = "TESTING 123 GARAGE\n"
            assert file.read() == correct

    def test_record_tabular(self, mock_datetime):
        fake_timestamp(mock_datetime)

        self.tabular.record("foo", 100)
        self.tabular.record("bar", 55)

        self.text_output.record(self.tabular)
        self.text_output.dump()

        with open(self.log_file.name, "r") as file:
            tab = "---  ---\n" "bar   55\n" "foo  100\n" "---  ---\n"  # yapf: disable
            assert file.read() == tab

    def test_record_unknown(self, mock_datetime):
        with self.assertRaises(ValueError):
            self.text_output.record(dict())