Exemplo n.º 1
0
    def test_metadata_dir(self):
        user_home = os.path.expanduser("~")

        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals("metadata", rsp.metadata_dir)
        self.assertEquals(rsp.abs_metadata_dir(),
                          os.path.join(user_home, "metadata"))

        resource_dir = user_home

        rsp = RsParameters(metadata_dir=os.path.join("foo", "md1"),
                           resource_dir=resource_dir)
        # print(rsp.abs_metadata_dir())
        self.assertEquals(rsp.abs_metadata_dir(),
                          os.path.join(resource_dir, "foo", "md1"))
        # @ToDo test for windows pathnames: 'foo\md1', 'C:foo\bar\baz'

        here = os.path.dirname(__file__)
        rsp.resource_dir = here
        self.assertEquals(rsp.abs_metadata_dir(),
                          os.path.join(here, "foo", "md1"))

        # contamination test
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(rsp2.abs_metadata_dir(),
                          os.path.join(here, "foo", "md1"))

        with self.assertRaises(Exception) as context:
            rsp.metadata_dir = os.path.expanduser("~")
        # print(context.exception)
        self.assertEquals(
            "Invalid value for metadata_dir: path should not be absolute: " +
            os.path.expanduser("~"), context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        with self.assertRaises(Exception) as context:
            rsp.metadata_dir = "/foo/bar"
        # print(context.exception)
        self.assertEquals(
            "Invalid value for metadata_dir: path should not be absolute: /foo/bar",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        # cannot check if metadata_dir will be a directory, because relative to resource_dir
        # this = os.path.basename(__file__)
        # with self.assertRaises(Exception) as context:
        #     rsp.metadata_dir = this
        # #print(context.exception)
        # self.assertIsInstance(context.exception, ValueError)

        self.save_configuration_test(rsp)
Exemplo n.º 2
0
    def test_history_dir(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(None, rsp.history_dir)

        rsp = RsParameters(history_dir="foo/bar/baz")
        self.assertEquals("foo/bar/baz", rsp.history_dir)

        # contamination test
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals("foo/bar/baz", rsp2.history_dir)

        expected = os.path.join(rsp.abs_metadata_dir(), "foo/bar/baz")
        self.assertEquals(expected, rsp.abs_history_dir())

        rsp.history_dir = None
        self.assertIsNone(rsp.abs_history_dir())

        rsp.history_dir = "history"
        self.assertEquals("history", rsp.history_dir)

        rsp.history_dir = ""
        self.assertEquals(None, rsp.history_dir)

        with self.assertRaises(Exception) as context:
            rsp.history_dir = 42
        #print(context.exception)
        self.assertEquals(
            "Value for history_dir should be string. 42 is <class 'int'>",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        self.save_configuration_test(rsp)