Beispiel #1
0
    def test_prepare_does_not_build_output_dir_if_exists(self):
        cfg = Config(self.__build_args(directory="barrels"))

        with patch("os.path.exists") as e, patch("os.mkdir") as m:
            e.return_value = True
            cfg.prepare_project_dir()
            m.assert_not_called()
Beispiel #2
0
    def test_open_file_passes_file_to_callback(self):
        cfg = Config(self.__build_args())

        with patch("builtins.open", mock_open(read_data="A Test file")):
            cfg.open_file(
                "mockfile", "r", lambda f: self.assertEqual("A Test file", f.readline())
            )
Beispiel #3
0
    def test_open_file_calls_callback_with_expected_stream(self):
        cfg = Config(self.__build_args())
        cb = Mock()

        with patch("builtins.open", mock_open(read_data="A Test file")):
            cfg.open_file("mockfile", "r", cb)

        cb.assert_called_once()
Beispiel #4
0
    def test_open_file_can_write(self):
        cfg = Config(self.__build_args())
        m = mock_open()

        with patch("builtins.open", m):
            cfg.open_file("mockfile", "w", lambda f: f.write("some data"))

        m.assert_called_once_with("mockfile", "w")
        handle = m()
        handle.write.assert_called_once_with("some data")
Beispiel #5
0
    def test_package_from_cfg_is_valid(self):
        self.__mock_path.return_value = True
        m = mock_open(read_data=self.__build_cfg(package="pack.txt"))
        with patch("builtins.open", m):
            cfg = Config(self.__build_args())

        self.assertEqual("pack.txt", cfg.package)
Beispiel #6
0
    def test_reads_default_config_file_if_exists(self):
        self.__mock_path.return_value = True
        m = mock_open(read_data="")
        with patch("builtins.open", m):
            Config(self.__build_args())

        m.assert_called_once_with("mbgetcfg.ini", "r")
Beispiel #7
0
    def test_manifest_from_cfg_is_valid(self):
        self.__mock_path.return_value = True
        m = mock_open(read_data=self.__build_cfg(manifest="man.xml"))
        with patch("builtins.open", m):
            cfg = Config(self.__build_args())

        self.assertEqual("man.xml", cfg.manifest)
Beispiel #8
0
    def test_jungle_from_cfg_is_valid(self):
        self.__mock_path.return_value = True
        m = mock_open(read_data=self.__build_cfg(jungle="brl.jungle"))
        with patch("builtins.open", m):
            cfg = Config(self.__build_args())

        self.assertEqual("brl.jungle", cfg.jungle)
Beispiel #9
0
    def test_reads_config_file_from_args(self):
        self.__mock_path.return_value = True
        m = mock_open(read_data="")
        with patch("builtins.open", m):
            Config(self.__build_args(config="test.ini"))

        m.assert_called_once_with("test.ini", "r")
Beispiel #10
0
    def test_barrel_dir_from_cfg_is_valid(self):
        self.__mock_path.return_value = True
        m = mock_open(read_data=self.__build_cfg(directory="barrels"))
        with patch("builtins.open", m):
            cfg = Config(self.__build_args())

        self.assertEqual("barrels", cfg.barrel_dir)
Beispiel #11
0
 def test_token_from_env_if_arg_is_none(self):
     with patch.dict("os.environ", {"MBGET_GH_TOKEN": "125aeb"}):
         cfg = Config(self.__build_args(token=None))
         self.assertEqual("125aeb", cfg.token)
Beispiel #12
0
 def test_token_prioritizes_args_over_env(self):
     with patch.dict("os.environ", {"MBGET_GH_TOKEN": "125aeb"}):
         cfg = Config(self.__build_args(token="12345abc"))
         self.assertEqual("12345abc", cfg.token)
Beispiel #13
0
 def test_default_barrel_dir_is_valid(self):
     cfg = Config(self.__build_args())
     self.assertEqual(".mbpkg", cfg.barrel_dir)
Beispiel #14
0
 def test_manifest_is_valid(self):
     cfg = Config(self.__build_args(manifest="mfst.xml"))
     self.assertEqual("mfst.xml", cfg.manifest)
Beispiel #15
0
 def test_token_is_valid(self):
     cfg = Config(self.__build_args(token="12345abc"))
     self.assertEqual("12345abc", cfg.token)
Beispiel #16
0
 def test_can_init_config(self):
     Config(self.__build_args())
Beispiel #17
0
 def test_package_is_valid(self):
     cfg = Config(self.__build_args(package="pck.txt"))
     self.assertEqual("pck.txt", cfg.package)
Beispiel #18
0
 def test_default_package_is_valid(self):
     cfg = Config(self.__build_args())
     self.assertEqual("packages.txt", cfg.package)
Beispiel #19
0
 def test_barrel_dir_is_valid(self):
     cfg = Config(self.__build_args(directory="barrels"))
     self.assertEqual("barrels", cfg.barrel_dir)
Beispiel #20
0
 def test_default_jungle_is_valid(self):
     cfg = Config(self.__build_args())
     self.assertEqual("barrels.jungle", cfg.jungle)
Beispiel #21
0
 def test_jungle_is_valid(self):
     cfg = Config(self.__build_args(jungle="brrls.jungle"))
     self.assertEqual("brrls.jungle", cfg.jungle)
Beispiel #22
0
 def __init__(self, config: Config):
     self.package_map: Dict[str, str] = {}
     config.open_file(config.package, "r", self.__parse_packages)
Beispiel #23
0
 def test_token_is_none(self):
     cfg = Config(self.__build_args(token=None))
     self.assertIsNone(cfg.token)