text:
<?php
namespace Origin\Autoload {

	use \Origin\Autoload\AutoloadException;

	class Autoload {
		/*
		* Static paths to include files (usually files which are not namespaced or have specific namespaces that would not normally load correctly).
		* Ideally eventually this will be moved to some sort of a config file.
		* If you have another autoloader file I'd personally suggest putting it on line 8 of incluides/loader.php
		*/
		public static $static_paths = array();

		public static $autoload_paths = array(
			'includes/Library/%s.php',
			'includes/Library/%s.class.php',
			'includes/%s.php',
			'includes/%s.class.php',
			'%s.php',
			'%s.class.php',
		);
		/*
		*
		*/
		public static function Load($class){
			if(self::StaticPath($class)){
				return true;
			}

			$path = explode(constant('NAMESPACE'), $class);
			return self::LoadClassOrDie(implode(DIRECTORY_SEPARATOR, $path));
		}

		/*
		* @params - $class
		* Attempts to look for a static path match. If found it will load that class.
		* @return boolean (Successfully loaded a class).
		*/
		private static function StaticPath($class){
			// Direct comparison.
			if(in_array($class, self::$static_paths)){
				require_once(self::$static_paths[$class]);
				return true;
			}

			// If we're this far in the direct comparison has failed. So we'll look for "off by one".
			foreach(self::$static_paths as $namespace => $path){
				if(stripos($namespace, $class) !== false){
					if(self::Difference((strlen($namespace) - strlen($class)), -1, 1)){
						require_once(self::$static_paths[$class]);
						return true;
					}
				}
			}

			return false;
		}

		/*
		* @params - $val, $min, $max
		* Determines if the value is greater than min and less than max.
		* @return boolean ($val is between $min and $max)
		*/
		private static function Difference($val, $min, $max) {
			return ($val >= $min && $val <= $max);
		}

		/*
		* @params - Path to the file without the file's extension.
		* Attempts to find a file matching the path passed to it based on possible autoload locations ($autoload_paths).
		* @return boolean (Successfully found and loaded file.)
		*
		* NOTE: Will throw AutoloadException if the file does not exist or the path is invalid.
		*/
		const GENERIC_ERROR = 'Autoload Failure: Invalid path specified unable to load %s from %s on line %s.';
		private static function LoadClassOrDie($path){
			foreach(self::$autoload_paths as $location){
				if(file_exists(sprintf($location, $path))){
					require_once(sprintf($location, $path));
					return true;
				}
			}

			if (!(stripos($path, 'Smarty_Internal_Compile') !== false)) {
				$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2];
				$error = sprintf(static::GENERIC_ERROR, $path, $backtrace['file'], $backtrace['line']);
				throw new AutoloadException($error);
			}
		}
	}

	class AutoloadException extends \Exception {}
}


text:
package trader;

import eu.verdelhan.ta4j.Tick;

/**
 * Created by jkahn on 12/21/15.
 *
 * @author Joshua Kahn
 */
public interface TickListener {

    /**
     * Send a {@link eu.verdelhan.ta4j.Tick Tick} to all listeners.
     *
     * @param tick the {@link eu.verdelhan.ta4j.Tick Tick} to send to all
     *             listeners.
     */
    void tickReceived(Tick tick);

}

redpajama_set_name: RedPajamaGithub


text:
using System;
using System.Runtime.CompilerServices;
using QUnit;

namespace CoreLib.TestScript.SimpleTypes {
	[TestFixture]
	public class CharTests {
		[Test]
		public void TypePropertiesAreInt32() {
			Assert.AreEqual(typeof(char).FullName, "ss.Int32");
			Assert.IsFalse(typeof(char).IsClass);
			Assert.IsTrue(typeof(IComparable<byte>).IsAssignableFrom(typeof(char)));
			Assert.IsTrue(typeof(IEquatable<byte>).IsAssignableFrom(typeof(char)));
			Assert.IsTrue(typeof(IFormattable).IsAssignableFrom(typeof(char)));

			var interfaces = typeof(char).GetInterfaces();
			Assert.AreEqual(interfaces.Length, 3);
			Assert.IsTrue(interfaces.Contains(typeof(IComparable<char>)));
			Assert.IsTrue(interfaces.Contains(typeof(IEquatable<char>)));
			Assert.IsTrue(interfaces.Contains(typeof(IFormattable)));
		}

		[IncludeGenericArguments]
		private T GetDefaultValue<T>() {
			return default(T);
		}

		[Test]
		public void DefaultValueWorks() {
			Assert.AreEqual((int)GetDefaultValue<char>(), 0);
		}

		[Test]
		public void DefaultConstructorReturnsZero() {
			Assert.AreStrictEqual((int)new char(), 0);
		}

		[Test]
		public void CreatingInstanceReturnsZero() {
			Assert.AreStrictEqual((int)Activator.CreateInstance<char>(), 0);
		}

		[Test]
		public void ConstantsWork() {
			Assert.AreEqual((int)char.MinValue, 0);
			Assert.AreEqual((int)char.MaxValue, 65535);
		}

		[Test]
		public void CharComparisonWorks() {
			char a = 'a', a2 = 'a', b = 'b';
			Assert.IsTrue(a == a2);
			Assert.IsFalse(a == b);
			Assert.IsFalse(a != a2);
			Assert.IsTrue(a != b);
			Assert.IsFalse(a < a2);
			Assert.IsTrue(a < b);
		}

		[Test]
		public void CharParseWorks() {
			Assert.AreEqual(char.Parse("abc"), (int)'a');
		}

		[Test]
		public void FormatWorks() {
			Assert.AreEqual('\x23'.Format("x4"), "0023");
		}

		[Test]
		public void IFormattableToStringWorks() {
			Assert.AreEqual('\x23'.ToString("x4"), "0023");
		}

		[Test]
		public void LocaleFormatWorks() {
			Assert.AreEqual('\x23'.LocaleFormat("x4"), "0023");
		}

		[Test]
		public void ToStringWorks() {
			Assert.AreEqual('A'.ToString(), "A");
		}

		[Test]
		public void ToLocaleStringWorks() {
			Assert.AreEqual('A'.ToLocaleString(), "A");
		}

		[Test]
		public void CastCharToStringWorks() {
			Assert.AreEqual((string)'c', "c");
		}

		[Test]
		public void GetHashCodeWorks() {
			Assert.AreEqual   ('0'.GetHashCode(), '0'.GetHashCode());
			Assert.AreEqual   ('1'.GetHashCode(), '1'.GetHashCode());
			Assert.AreNotEqual('0'.GetHashCode(), '1'.GetHashCode());
		}

		[Test]
		public void EqualsWorks() {
			Assert.IsTrue ('0'.Equals((int)'0'));
			Assert.IsFalse('1'.Equals((int)'0'));
			Assert.IsFalse('0'.Equals((int)'1'));
			Assert.IsTrue ('1'.Equals((int)'1'));
		}

		[Test]
		public void IEquatableEqualsWorks() {
			Assert.IsTrue ('0'.Equals('0'));
			Assert.IsFalse('1'.Equals('0'));
			Assert.IsFalse('0'.Equals('1'));
			Assert.IsTrue ('1'.Equals('1'));
		}

		[Test]
		public void CompareToWorks() {
			Assert.IsTrue('1'.CompareTo('0') > 0);
			Assert.IsTrue('0'.CompareTo('1') < 0);
			Assert.IsTrue('0'.CompareTo('0') == 0);
			Assert.IsTrue('1'.CompareTo('1') == 0);
		}

		[Test]
		public void IsLowerWorks() {
			Assert.IsTrue (char.IsLower('a'), "#1");
			Assert.IsFalse(char.IsLower('A'), "#2");
			Assert.IsFalse(char.IsLower('3'), "#3");
		}

		[Test]
		public void IsUpperWorks() {
			Assert.IsTrue (char.IsUpper('A'), "#1");
			Assert.IsFalse(char.IsUpper('a'), "#2");
			Assert.IsFalse(char.IsUpper('3'), "#3");
		}

		[Test]
		public void ToLowerWorks() {
			Assert.AreEqual((int)char.ToLower('A'), (int)'a');
			Assert.AreEqual((int)char.ToLower('a'), (int)'a');
			Assert.AreEqual((int)char.ToLower('3'), (int)'3');
		}

		[Test]
		public void ToUpperWorks() {
			Assert.AreEqual((int)char.ToUpper('A'), (int)'A');
			Assert.AreEqual((int)char.ToUpper('a'), (int)'A');
			Assert.AreEqual((int)char.ToUpper('3'), (int)'3');
		}

		[Test]
		public void IsDigitWorks() {
			Assert.IsTrue (char.IsDigit('0'), "#1");
			Assert.IsFalse(char.IsDigit('.'), "#2");
			Assert.IsFalse(char.IsDigit('A'), "#3");
		}

		[Test]
		public void IsWhiteSpaceWorks() {
			Assert.IsTrue (char.IsWhiteSpace(' '),  "#1");
			Assert.IsTrue (char.IsWhiteSpace('\n'), "#2");
			Assert.IsFalse(char.IsWhiteSpace('A'),  "#3");
		}

		[Test]
		public void IsDigitWithStringAndIndexWorks()
		{
			Assert.IsTrue(char.IsDigit("abc0def", 3), "#1");
			Assert.IsTrue(char.IsDigit("1", 0), "#2");
			Assert.IsTrue(char.IsDigit("abcdef5", 6), "#3");
			Assert.IsTrue(char.IsDigit("9abcdef", 0), "#4");
			Assert.IsFalse(char.IsDigit(".012345", 0), "#5");
			Assert.IsFalse(char.IsDigit("012345.", 6), "#6");
			Assert.IsFalse(char.IsDigit("012.345", 3), "#7");
		}

		[Test]
		public void IsWhiteSpaceWithStringAndIndexWorks()
		{
			Assert.IsTrue(char.IsWhiteSpace("abc def", 3), "#1");
			Assert.IsTrue(char.IsWhiteSpace("\t", 0), "#2");
			Assert.IsTrue(char.IsWhiteSpace("abcdef\r", 6), "#3");
			Assert.IsTrue(char.IsWhiteSpace("\nabcdef", 0), "#4");
			Assert.IsFalse(char.IsWhiteSpace(".\r\n     ", 0), "#5");
			Assert.IsFalse(char.IsWhiteSpace("\r\n    .", 6), "#6");
			Assert.IsFalse(char.IsWhiteSpace("\r  .\n  ", 3), "#7");
		}
	}
}


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>com.sap.integration.utils</title>
<meta name="date" content="2015-11-11">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">

com.sap.integration.utils

Classes

DateUtil

HttpsCall

JsonUtil

SimpleResponse

UrlBuilder


text:
package uk.co.nimp;

/**
 * Created by seb on 8/18/14.
 */
public class BooleanFunction {
    final boolean[] outputs;
    Boolean isBalanced=null;
    Integer numberOf0 = null;
    Integer numberOf1 = null;
    Double probOf0=null;
    Double probOf1=null;

    private BooleanFunction(boolean[] outputs){
        if(isPowerOf2(outputs.length)) throw new RuntimeException("Length must be a power of 2: got "+outputs.length);
        this.outputs = outputs.clone();
    }

    public boolean isBalanced() {
        if(null==isBalanced) {
            isBalanced=getNumberOf1()==outputs.length/2;
        }
        return isBalanced;
    }

    public Integer getNumberOf1() {
        if(null==numberOf1){
            numberOf1=numberOf1(outputs);
            numberOf0=outputs.length-numberOf1;
            probOf1=((double)numberOf1)/outputs.length;
            probOf0=1-probOf1;
        }
        return numberOf1;
    }

    public Integer getNumberOf0() {
        if(null==numberOf1) getNumberOf1();
        return numberOf0;
    }

    public double getProbOf1(){
        if(null==numberOf1) getNumberOf1();
        return probOf1;
    }

    public double getProbOf0(){
        if(null==numberOf1) getNumberOf1();
        return probOf0;
    }

    public static boolean isBalanced(boolean[] f){
        return numberOf1(f)==f.length/2;
    }

    public static int numberOf1(boolean[] f){
        int out=0;
        for(int i=0;i<f.length;i++){
            out+= f[i] ? 1 : 0;
        }
        return out;
    }

    public static int numberOf0(boolean[] f){
        return f.length-numberOf1(f);
    }

    public static boolean isPowerOf2(int length) {
        if(length<2) return false;
        int tmp=length-1;
        int x=tmp & length;
        return 0==x;
    }
}


text:
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Numeric.Positive (
        Positive,
        positive,
        nonEmptyLength,
  ) where

import Numeric.Natural
import Data.Semigroup
import qualified Data.List.NonEmpty as NonEmpty

newtype Positive = Positive { getPositive :: Natural } deriving
    (
    Eq,
    Ord,
    -- Data,
    Real
    -- Ix,
    -- Typeable,
    -- Bits,
    -- Hashable,
    -- Whole
    )

instance Show Positive where
  show (Positive n) = show n

instance Read Positive where
  readsPrec d = map (\(n, s) -> (fromInteger n, s)) . readsPrec d

instance Integral Positive where
  toInteger (Positive a) = toInteger a
  Positive a `quotRem` Positive b = (fromIntegral $ a `quot` b, fromIntegral $ a `rem` b)
  Positive a `divMod` Positive b  = (fromIntegral $ a `div` b, fromIntegral $ a `mod` b)

instance Enum Positive where
  toEnum   = fromIntegral
  fromEnum = fromIntegral

instance Num Positive where
  Positive n + Positive m = Positive (n + m)
  Positive n * Positive m = Positive (n * m)
  Positive n - Positive m
    | r <  0 = error "Positive.(-): negative result"
    | r == 0 = error "Positive.(-): result zero"
    | otherwise   = Positive r
    where
      r = n - m
  abs      = id
  signum _ = 1
  fromInteger n
    | n >  0 = Positive (fromInteger n)
    | n == 0 = error "Positive.fromInteger: zero"
    | n <  0 = error "Positive.fromInteger: negative"

positive :: a -> (a -> a) -> Positive -> a
positive a f 1 = f a
positive a f n = f (positive a f $ pred n)

nonEmptyLength :: NonEmpty.NonEmpty a -> Positive
nonEmptyLength = fromIntegral . NonEmpty.length

-- _positive :: Integral a => Prism' a Positive
-- _positive :: prism' fromIntegral (\x -> if x > 0 then Just (fromInteger x :: Positive) else Nothing)

-- _nonEmpty :: Prism [a] [b] (NonEmpty a) (NonEmpty b)
-- _nonEmpty :: prism' NonEmpty.toList (\x -> if lenght x > 0 then Just (NonEmpty.fromList x) else Nothing)


text:
import datetime
from typing import List

import pandas as pd
import pytest
from ruamel.yaml import YAML

import great_expectations.exceptions as ge_exceptions
from great_expectations.core.batch import (
    Batch,
    BatchDefinition,
    BatchSpec,
    RuntimeBatchRequest,
)
from great_expectations.core.batch_spec import (
    PathBatchSpec,
    RuntimeDataBatchSpec,
    RuntimeQueryBatchSpec,
    S3BatchSpec,
)
from great_expectations.core.id_dict import IDDict
from great_expectations.data_context.util import instantiate_class_from_config
from great_expectations.datasource import Datasource
from great_expectations.datasource.data_connector import RuntimeDataConnector

yaml = YAML()

@pytest.fixture
def basic_datasource_with_assets(tmp_path_factory):
    basic_datasource: Datasource = instantiate_class_from_config(
        config=yaml.load(
            """
class_name: Datasource

data_connectors:
    runtime:
        class_name: RuntimeDataConnector
        batch_identifiers:
            - hour
            - minute
        assets:
            asset_a:
                batch_identifiers:
                    - day
                    - month
            asset_b:
                batch_identifiers:
                    - day
                    - month
                    - year
execution_engine:
    class_name: PandasExecutionEngine
    """,
        ),
        runtime_environment={
            "name": "my_datasource",
        },
        config_defaults={
            "module_name": "great_expectations.datasource",
        },
    )
    return basic_datasource

def test_self_check(basic_datasource):
    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )
    assert test_runtime_data_connector.self_check() == {
        "class_name": "RuntimeDataConnector",
        "data_asset_count": 0,
        "data_assets": {},
        "example_data_asset_names": [],
        "example_unmatched_data_references": [],
        "note": "RuntimeDataConnector will not have data_asset_names until they are "
        "passed in through RuntimeBatchRequest",
        "unmatched_data_reference_count": 0,
    }

def test_self_check_named_assets(basic_datasource_with_assets):
    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource_with_assets.data_connectors["runtime"]
    )
    assert test_runtime_data_connector.self_check() == {
        "class_name": "RuntimeDataConnector",
        "data_asset_count": 2,
        "example_data_asset_names": ["asset_a", "asset_b"],
        "data_assets": {
            "asset_a": {"batch_definition_count": 0, "example_data_references": []},
            "asset_b": {"batch_definition_count": 0, "example_data_references": []},
        },
        "unmatched_data_reference_count": 0,
        "example_unmatched_data_references": [],
    }

def test_new_self_check_after_adding_named_asset_a(
    basic_datasource_with_assets, test_df_pandas
):
    runtime_data_connector: RuntimeDataConnector = (
        basic_datasource_with_assets.data_connectors["runtime"]
    )
    # noinspection PyUnusedLocal
    res: List[
        BatchDefinition
    ] = runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=RuntimeBatchRequest(
            datasource_name=basic_datasource_with_assets.name,
            data_connector_name="runtime",
            data_asset_name="asset_a",
            batch_identifiers={"month": 4, "day": 1},
            runtime_parameters={"batch_data": test_df_pandas},
        )
    )
    assert runtime_data_connector.self_check() == {
        "class_name": "RuntimeDataConnector",
        "data_asset_count": 2,
        "example_data_asset_names": ["asset_a", "asset_b"],
        "data_assets": {
            "asset_a": {
                "batch_definition_count": 1,
                "example_data_references": ["4-1"],
            },
            "asset_b": {"batch_definition_count": 0, "example_data_references": []},
        },
        "unmatched_data_reference_count": 0,
        "example_unmatched_data_references": [],
    }

def test_new_self_check_after_adding_new_asset_c(
    basic_datasource_with_assets, test_df_pandas
):
    runtime_data_connector: RuntimeDataConnector = (
        basic_datasource_with_assets.data_connectors["runtime"]
    )
    res: List[
        BatchDefinition
    ] = runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=RuntimeBatchRequest(
            datasource_name=basic_datasource_with_assets.name,
            data_connector_name="runtime",
            data_asset_name="asset_c",
            batch_identifiers={"hour": 12, "minute": 15},
            runtime_parameters={"batch_data": test_df_pandas},
        )
    )
    assert runtime_data_connector.self_check() == {
        "class_name": "RuntimeDataConnector",
        "data_asset_count": 3,
        "example_data_asset_names": ["asset_a", "asset_b", "asset_c"],
        "data_assets": {
            "asset_a": {"batch_definition_count": 0, "example_data_references": []},
            "asset_b": {"batch_definition_count": 0, "example_data_references": []},
            "asset_c": {
                "batch_definition_count": 1,
                "example_data_references": ["12-15"],
            },
        },
        "unmatched_data_reference_count": 0,
        "example_unmatched_data_references": [],
    }

def test_add_batch_identifiers_correct(basic_datasource_with_assets):
    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource_with_assets.data_connectors["runtime"]
    )
    assert test_runtime_data_connector._batch_identifiers == {
        "runtime": ["hour", "minute"],
        "asset_a": ["day", "month"],
        "asset_b": ["day", "month", "year"],
    }

def test_batch_identifiers_missing_completely():
    # missing from base DataConnector
    with pytest.raises(ge_exceptions.DataConnectorError) as data_connector_error:
        instantiate_class_from_config(
            config=yaml.load(
                """
class_name: Datasource
data_connectors:
    runtime:
        class_name: RuntimeDataConnector
execution_engine:
    class_name: PandasExecutionEngine
    """,
            ),
            runtime_environment={
                "name": "my_datasource",
            },
            config_defaults={
                "module_name": "great_expectations.datasource",
            },
        )
    expected_error_message: str = """
        RuntimeDataConnector "runtime" requires batch_identifiers to be configured, either at the DataConnector or Asset-level.
    """
    assert str(data_connector_error.value).strip() == expected_error_message.strip()

def test_batch_identifiers_missing_from_named_asset():
    with pytest.raises(ge_exceptions.DataConnectorError) as data_connector_error:
        basic_datasource: Datasource = instantiate_class_from_config(
            config=yaml.load(
                """
class_name: Datasource
data_connectors:
    runtime:
        class_name: RuntimeDataConnector
        batch_identifiers:
            - hour
            - minute
        assets:
            asset_a:
execution_engine:
    class_name: PandasExecutionEngine
    """,
            ),
            runtime_environment={
                "name": "my_datasource",
            },
            config_defaults={
                "module_name": "great_expectations.datasource",
            },
        )

    expected_error_message: str = """
        RuntimeDataConnector "runtime" requires batch_identifiers to be configured when specifying Assets.
        """
    assert str(data_connector_error.value).strip() == expected_error_message.strip()

def test_error_checking_unknown_datasource(basic_datasource):
    test_df: pd.DataFrame = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    # Test for an unknown datasource
    with pytest.raises(ValueError):
        # noinspection PyUnusedLocal
        batch_definition_list: List[
            BatchDefinition
        ] = test_runtime_data_connector.get_batch_definition_list_from_batch_request(
            batch_request=RuntimeBatchRequest(
                datasource_name="non_existent_datasource",
                data_connector_name="test_runtime_data_connector",
                data_asset_name="my_data_asset",
                runtime_parameters={"batch_data": test_df},
                batch_identifiers={"airflow_run_id": "first"},
            )
        )

def test_error_checking_unknown_data_connector(basic_datasource):
    test_df: pd.DataFrame = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    # Test for an unknown data_connector
    with pytest.raises(ValueError):
        # noinspection PyUnusedLocal
        batch_definition_list: List[
            BatchDefinition
        ] = test_runtime_data_connector.get_batch_definition_list_from_batch_request(
            batch_request=RuntimeBatchRequest(
                datasource_name=basic_datasource.name,
                data_connector_name="non_existent_data_connector",
                data_asset_name="my_data_asset",
                runtime_parameters={"batch_data": test_df},
                batch_identifiers={"airflow_run_id": "first"},
            )
        )

def test_error_checking_missing_runtime_parameters(basic_datasource):
    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    # test for missing runtime_parameters arg
    with pytest.raises(TypeError):
        # noinspection PyUnusedLocal, PyArgumentList
        batch_definition_list: List[
            BatchDefinition
        ] = test_runtime_data_connector.get_batch_definition_list_from_batch_request(
            batch_request=RuntimeBatchRequest(
                datasource_name=basic_datasource.name,
                data_connector_name="test_runtime_data_connector",
                data_asset_name="my_data_asset",
                batch_identifiers={"pipeline_stage_name": "munge"},
            )
        )

def test_asset_is_name_batch_identifier_correctly_used(
    basic_datasource_with_assets, test_df_pandas
):
    """
    Using asset_a, which is named in the RuntimeDataConnector configuration, and using batch_identifier that is named.
    """
    runtime_data_connector: RuntimeDataConnector = (
        basic_datasource_with_assets.data_connectors["runtime"]
    )
    res: List[
        BatchDefinition
    ] = runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=RuntimeBatchRequest(
            datasource_name=basic_datasource_with_assets.name,
            data_connector_name="runtime",
            data_asset_name="asset_a",
            batch_identifiers={"month": 4, "day": 1},
            runtime_parameters={"batch_data": test_df_pandas},
        )
    )
    assert len(res) == 1
    assert res[0] == BatchDefinition(
        datasource_name="my_datasource",
        data_connector_name="runtime",
        data_asset_name="asset_a",
        batch_identifiers=IDDict({"month": 4, "day": 1}),
    )

def test_asset_is_named_but_batch_identifier_in_other_asset(
    basic_datasource_with_assets, test_df_pandas
):
    runtime_data_connector: RuntimeDataConnector = (
        basic_datasource_with_assets.data_connectors["runtime"]
    )
    with pytest.raises(ge_exceptions.DataConnectorError) as data_connector_error:
        runtime_data_connector.get_batch_definition_list_from_batch_request(
            batch_request=RuntimeBatchRequest(
                datasource_name=basic_datasource_with_assets.name,
                data_connector_name="runtime",
                data_asset_name="asset_a",
                batch_identifiers={
                    "year": 2022,
                    "month": 4,
                    "day": 1,
                },  # year is only defined for asset_b
                runtime_parameters={"batch_data": test_df_pandas},
            )
        )
    expected_error_message: str = """
                Data Asset asset_a was invoked with one or more batch_identifiers
                that were not configured for the asset.

                The Data Asset was configured with : ['day', 'month']
                It was invoked with : ['year', 'month', 'day']
    """
    assert str(data_connector_error.value).strip() == expected_error_message.strip()

def test_asset_is_named_but_batch_identifier_not_defined_anywhere(
    basic_datasource_with_assets, test_df_pandas
):
    runtime_data_connector: RuntimeDataConnector = (
        basic_datasource_with_assets.data_connectors["runtime"]
    )
    with pytest.raises(ge_exceptions.DataConnectorError) as data_connector_error:
        runtime_data_connector.get_batch_definition_list_from_batch_request(
            batch_request=RuntimeBatchRequest(
                datasource_name=basic_datasource_with_assets.name,
                data_connector_name="runtime",
                data_asset_name="asset_a",
                batch_identifiers={"blorg": 2022},  # blorg is not defined anywhere
                runtime_parameters={"batch_data": test_df_pandas},
            )
        )
    expected_error_message: str = """
                Data Asset asset_a was invoked with one or more batch_identifiers
                that were not configured for the asset.

                The Data Asset was configured with : ['day', 'month']
                It was invoked with : ['blorg']
    """
    assert str(data_connector_error.value).strip() == expected_error_message.strip()

def test_named_asset_is_trying_to_use_batch_identifier_defined_in_data_connector(
    basic_datasource_with_assets, test_df_pandas
):
    runtime_data_connector: RuntimeDataConnector = (
        basic_datasource_with_assets.data_connectors["runtime"]
    )
    with pytest.raises(ge_exceptions.DataConnectorError) as data_connector_error:
        runtime_data_connector.get_batch_definition_list_from_batch_request(
            batch_request=RuntimeBatchRequest(
                datasource_name=basic_datasource_with_assets.name,
                data_connector_name="runtime",
                data_asset_name="asset_a",
                batch_identifiers={
                    "month": 4,
                    "day": 1,
                    "hour": 12,
                },  # hour is a data-connector level batch identifier
                runtime_parameters={"batch_data": test_df_pandas},
            )
        )
    expected_error_message: str = """
                Data Asset asset_a was invoked with one or more batch_identifiers
                that were not configured for the asset.

                The Data Asset was configured with : ['day', 'month']
                It was invoked with : ['month', 'day', 'hour']
    """
    assert str(data_connector_error.value).strip() == expected_error_message.strip()

def test_runtime_batch_request_trying_to_use_batch_identifier_defined_at_asset_level(
    basic_datasource_with_assets, test_df_pandas
):
    runtime_data_connector: RuntimeDataConnector = (
        basic_datasource_with_assets.data_connectors["runtime"]
    )
    with pytest.raises(ge_exceptions.DataConnectorError) as data_connector_error:
        runtime_data_connector.get_batch_definition_list_from_batch_request(
            batch_request=RuntimeBatchRequest(
                datasource_name=basic_datasource_with_assets.name,
                data_connector_name="runtime",
                data_asset_name="new_asset",
                batch_identifiers={
                    "year": 2022,
                    "hour": 12,
                    "minute": 30,
                },  # year is a asset_a level batch identifier
                runtime_parameters={"batch_data": test_df_pandas},
            )
        )
    expected_error_message: str = """
                RuntimeDataConnector runtime was invoked with one or more batch identifiers that do not
        appear among the configured batch identifiers.

                The RuntimeDataConnector was configured with : ['hour', 'minute']
                It was invoked with : ['year', 'hour', 'minute']
    """
    assert str(data_connector_error.value).strip() == expected_error_message.strip()

def test_error_checking_too_many_runtime_parameters(basic_datasource):
    test_df: pd.DataFrame = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    # test for too many runtime_parameters keys
    with pytest.raises(ge_exceptions.InvalidBatchRequestError):
        # noinspection PyUnusedLocal
        batch_definition_list: List[
            BatchDefinition
        ] = test_runtime_data_connector.get_batch_definition_list_from_batch_request(
            batch_request=RuntimeBatchRequest(
                datasource_name=basic_datasource.name,
                data_connector_name="test_runtime_data_connector",
                data_asset_name="my_data_asset",
                runtime_parameters={"batch_data": test_df, "path": "my_path"},
                batch_identifiers={"pipeline_stage_name": "munge"},
            )
        )

def test_batch_identifiers_and_batch_identifiers_success_all_keys_present(
    basic_datasource,
):
    test_df: pd.DataFrame = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})

    batch_identifiers: dict

    batch_identifiers = {
        "pipeline_stage_name": "core_processing",
        "airflow_run_id": 1234567890,
        "custom_key_0": "custom_value_0",
    }

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    # Verify that all keys in batch_identifiers are acceptable as batch_identifiers (using batch count).
    batch_request: dict = {
        "datasource_name": basic_datasource.name,
        "data_connector_name": test_runtime_data_connector.name,
        "data_asset_name": "IN_MEMORY_DATA_ASSET",
        "runtime_parameters": {"batch_data": test_df},
        "batch_identifiers": batch_identifiers,
    }
    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    batch_definition_list: List[
        BatchDefinition
    ] = test_runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=batch_request
    )

    assert len(batch_definition_list) == 1

def test_batch_identifiers_and_batch_identifiers_error_illegal_keys(
    basic_datasource,
):
    test_df: pd.DataFrame = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})

    batch_identifiers: dict

    batch_identifiers = {
        "pipeline_stage_name": "core_processing",
        "airflow_run_id": 1234567890,
        "custom_key_0": "custom_value_0",
        "custom_key_1": "custom_value_1",
    }

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    # Ensure that keys in batch_identifiers["batch_identifiers"] that are not among batch_identifiers declared in
    # configuration are not accepted.  In this test, all legal keys plus a single illegal key are present.
    batch_request: dict = {
        "datasource_name": basic_datasource.name,
        "data_connector_name": test_runtime_data_connector.name,
        "data_asset_name": "my_data_asset_name",
        "runtime_parameters": {"batch_data": test_df},
        "batch_identifiers": batch_identifiers,
    }
    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    with pytest.raises(ge_exceptions.DataConnectorError) as data_connector_error:
        # noinspection PyUnusedLocal
        batch_definition_list: List[
            BatchDefinition
        ] = test_runtime_data_connector.get_batch_definition_list_from_batch_request(
            batch_request=batch_request
        )
    expected_error_message: str = """
        RuntimeDataConnector test_runtime_data_connector was invoked with one or more batch identifiers that do not
        appear among the configured batch identifiers.

                The RuntimeDataConnector was configured with : ['pipeline_stage_name', 'airflow_run_id', 'custom_key_0']
                It was invoked with : ['pipeline_stage_name', 'airflow_run_id', 'custom_key_0', 'custom_key_1']
    """
    assert str(data_connector_error.value).strip() == expected_error_message.strip()

    batch_identifiers = {"batch_identifiers": {"unknown_key": "some_value"}}

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    # Ensure that keys in batch_identifiers["batch_identifiers"] that are not among batch_identifiers declared in configuration
    # are not accepted.  In this test, a single illegal key is present.
    batch_request: dict = {
        "datasource_name": basic_datasource.name,
        "data_connector_name": test_runtime_data_connector.name,
        "data_asset_name": "IN_MEMORY_DATA_ASSET",
        "runtime_parameters": {"batch_data": test_df},
        "batch_identifiers": batch_identifiers,
    }
    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    with pytest.raises(ge_exceptions.DataConnectorError) as data_connector_error:
        # noinspection PyUnusedLocal
        batch_definition_list: List[
            BatchDefinition
        ] = test_runtime_data_connector.get_batch_definition_list_from_batch_request(
            batch_request=batch_request
        )
    expected_error_message: str = """
        RuntimeDataConnector test_runtime_data_connector was invoked with one or more batch identifiers that do not
        appear among the configured batch identifiers.

                The RuntimeDataConnector was configured with : ['pipeline_stage_name', 'airflow_run_id', 'custom_key_0']
                It was invoked with : ['batch_identifiers']    """
    assert str(data_connector_error.value).strip() == expected_error_message.strip()

def test_get_available_data_asset_names(basic_datasource):
    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )
    expected_available_data_asset_names: List[str] = []
    available_data_asset_names: List[
        str
    ] = test_runtime_data_connector.get_available_data_asset_names()
    assert available_data_asset_names == expected_available_data_asset_names

def test_get_available_data_asset_names_named_assets(basic_datasource_with_assets):
    runtime_data_connector: RuntimeDataConnector = (
        basic_datasource_with_assets.data_connectors["runtime"]
    )
    assert runtime_data_connector.get_available_data_asset_names() == [
        "asset_a",
        "asset_b",
    ]

def test_get_available_data_asset_names_updating_after_batch_request(
    basic_datasource_with_assets,
):
    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource_with_assets.data_connectors["runtime"]
    )
    test_df: pd.DataFrame = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})

    # empty if data_connector has not been used
    assert test_runtime_data_connector.get_available_data_asset_names() == [
        "asset_a",
        "asset_b",
    ]

    batch_identifiers = {
        "hour": 12,
        "minute": 15,
    }

    batch_request: dict = {
        "datasource_name": basic_datasource_with_assets.name,
        "data_connector_name": test_runtime_data_connector.name,
        "data_asset_name": "my_new_data_asset_1",
        "runtime_parameters": {
            "batch_data": test_df,
        },
        "batch_identifiers": batch_identifiers,
    }
    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    # run with my_data_asset_1
    test_runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=batch_request
    )

    # updated to my_data_asset_1
    assert test_runtime_data_connector.get_available_data_asset_names() == [
        "asset_a",
        "asset_b",
        "my_new_data_asset_1",
    ]

    batch_identifiers = {
        "hour": 12,
        "minute": 30,
    }

    batch_request: dict = {
        "datasource_name": basic_datasource_with_assets.name,
        "data_connector_name": test_runtime_data_connector.name,
        "data_asset_name": "my_new_data_asset_2",
        "runtime_parameters": {
            "batch_data": test_df,
        },
        "batch_identifiers": batch_identifiers,
    }
    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    # run with my_data_asset_2
    test_runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=batch_request
    )

    # updated to my_data_asset_1 and my_data_asset_2
    assert test_runtime_data_connector.get_available_data_asset_names() == [
        "asset_a",
        "asset_b",
        "my_new_data_asset_1",
        "my_new_data_asset_2",
    ]

def test_data_references_cache_updating_after_batch_request(
    basic_datasource,
):
    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )
    test_df: pd.DataFrame = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})

    # empty if data_connector has not been used
    assert test_runtime_data_connector.get_available_data_asset_names() == []

    batch_identifiers = {
        "airflow_run_id": 1234567890,
    }

    batch_request: dict = {
        "datasource_name": basic_datasource.name,
        "data_connector_name": test_runtime_data_connector.name,
        "data_asset_name": "my_data_asset_1",
        "runtime_parameters": {
            "batch_data": test_df,
        },
        "batch_identifiers": batch_identifiers,
    }
    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    # run with my_data_asset_1
    test_runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=batch_request
    )

    assert test_runtime_data_connector._data_references_cache == {
        "my_data_asset_1": {
            "1234567890": [
                BatchDefinition(
                    datasource_name="my_datasource",
                    data_connector_name="test_runtime_data_connector",
                    data_asset_name="my_data_asset_1",
                    batch_identifiers=IDDict({"airflow_run_id": 1234567890}),
                )
            ],
        }
    }

    # update with
    test_df_new: pd.DataFrame = pd.DataFrame(data={"col1": [5, 6], "col2": [7, 8]})
    batch_identifiers = {
        "airflow_run_id": 987654321,
    }

    batch_request: dict = {
        "datasource_name": basic_datasource.name,
        "data_connector_name": test_runtime_data_connector.name,
        "data_asset_name": "my_data_asset_1",
        "runtime_parameters": {
            "batch_data": test_df_new,
        },
        "batch_identifiers": batch_identifiers,
    }
    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    # run with with new_data_asset but a new batch
    test_runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=batch_request
    )

    assert test_runtime_data_connector._data_references_cache == {
        "my_data_asset_1": {
            "1234567890": [
                BatchDefinition(
                    datasource_name="my_datasource",
                    data_connector_name="test_runtime_data_connector",
                    data_asset_name="my_data_asset_1",
                    batch_identifiers=IDDict({"airflow_run_id": 1234567890}),
                )
            ],
            "987654321": [
                BatchDefinition(
                    datasource_name="my_datasource",
                    data_connector_name="test_runtime_data_connector",
                    data_asset_name="my_data_asset_1",
                    batch_identifiers=IDDict({"airflow_run_id": 987654321}),
                )
            ],
        },
    }

    # new data_asset_name
    test_df_new_asset: pd.DataFrame = pd.DataFrame(
        data={"col1": [9, 10], "col2": [11, 12]}
    )
    batch_identifiers = {
        "airflow_run_id": 5555555,
    }

    batch_request: dict = {
        "datasource_name": basic_datasource.name,
        "data_connector_name": test_runtime_data_connector.name,
        "data_asset_name": "my_data_asset_2",
        "runtime_parameters": {
            "batch_data": test_df_new_asset,
        },
        "batch_identifiers": batch_identifiers,
    }
    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    # run with with new_data_asset but a new batch
    test_runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=batch_request
    )

    assert test_runtime_data_connector._data_references_cache == {
        "my_data_asset_1": {
            "1234567890": [
                BatchDefinition(
                    datasource_name="my_datasource",
                    data_connector_name="test_runtime_data_connector",
                    data_asset_name="my_data_asset_1",
                    batch_identifiers=IDDict({"airflow_run_id": 1234567890}),
                )
            ],
            "987654321": [
                BatchDefinition(
                    datasource_name="my_datasource",
                    data_connector_name="test_runtime_data_connector",
                    data_asset_name="my_data_asset_1",
                    batch_identifiers=IDDict({"airflow_run_id": 987654321}),
                )
            ],
        },
        "my_data_asset_2": {
            "5555555": [
                BatchDefinition(
                    datasource_name="my_datasource",
                    data_connector_name="test_runtime_data_connector",
                    data_asset_name="my_data_asset_2",
                    batch_identifiers=IDDict({"airflow_run_id": 5555555}),
                )
            ]
        },
    }

    assert test_runtime_data_connector.get_available_data_asset_names() == [
        "my_data_asset_1",
        "my_data_asset_2",
    ]

    assert test_runtime_data_connector.get_data_reference_list_count() == 3

def test_data_references_cache_updating_after_batch_request_named_assets(
    basic_datasource_with_assets,
):
    runtime_data_connector: RuntimeDataConnector = (
        basic_datasource_with_assets.data_connectors["runtime"]
    )

    test_df: pd.DataFrame = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})

    # if data_connector contains the assets in configuration
    assert runtime_data_connector.get_available_data_asset_names() == [
        "asset_a",
        "asset_b",
    ]

    batch_identifiers: dict = {"day": 1, "month": 1}
    batch_request: dict = {
        "datasource_name": basic_datasource_with_assets.name,
        "data_connector_name": runtime_data_connector.name,
        "data_asset_name": "asset_a",
        "runtime_parameters": {
            "batch_data": test_df,
        },
        "batch_identifiers": batch_identifiers,
    }

    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    # run with my_data_asset_1
    batch_definitions: List[
        BatchDefinition
    ] = runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=batch_request
    )
    assert batch_definitions == [
        BatchDefinition(
            datasource_name="my_datasource",
            data_connector_name="runtime",
            data_asset_name="asset_a",
            batch_identifiers=IDDict({"month": 1, "day": 1}),
        )
    ]
    assert runtime_data_connector._data_references_cache == {
        "asset_a": {
            "1-1": [
                BatchDefinition(
                    datasource_name="my_datasource",
                    data_connector_name="runtime",
                    data_asset_name="asset_a",
                    batch_identifiers=IDDict({"day": 1, "month": 1}),
                )
            ],
        }
    }
    batch_identifiers: dict = {"day": 1, "month": 2}
    batch_request: dict = {
        "datasource_name": basic_datasource_with_assets.name,
        "data_connector_name": runtime_data_connector.name,
        "data_asset_name": "asset_a",
        "runtime_parameters": {
            "batch_data": test_df,
        },
        "batch_identifiers": batch_identifiers,
    }
    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    # run with another batch under asset_a
    batch_definitions: List[
        BatchDefinition
    ] = runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=batch_request
    )
    assert batch_definitions == [
        BatchDefinition(
            datasource_name="my_datasource",
            data_connector_name="runtime",
            data_asset_name="asset_a",
            batch_identifiers=IDDict({"month": 2, "day": 1}),
        ),
    ]
    assert runtime_data_connector._data_references_cache == {
        "asset_a": {
            "1-1": [
                BatchDefinition(
                    datasource_name="my_datasource",
                    data_connector_name="runtime",
                    data_asset_name="asset_a",
                    batch_identifiers=IDDict({"day": 1, "month": 1}),
                )
            ],
            "1-2": [
                BatchDefinition(
                    datasource_name="my_datasource",
                    data_connector_name="runtime",
                    data_asset_name="asset_a",
                    batch_identifiers=IDDict({"day": 1, "month": 2}),
                )
            ],
        }
    }

def test_get_batch_definition_list_from_batch_request_length_one(
    basic_datasource,
):
    test_df: pd.DataFrame = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})

    batch_identifiers: dict = {
        "airflow_run_id": 1234567890,
    }

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    batch_request: dict = {
        "datasource_name": basic_datasource.name,
        "data_connector_name": test_runtime_data_connector.name,
        "data_asset_name": "my_data_asset",
        "runtime_parameters": {"batch_data": test_df},
        "batch_identifiers": batch_identifiers,
    }
    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    expected_batch_definition_list: List[BatchDefinition] = [
        BatchDefinition(
            datasource_name="my_datasource",
            data_connector_name="test_runtime_data_connector",
            data_asset_name="my_data_asset",
            batch_identifiers=IDDict(batch_identifiers),
        )
    ]

    batch_definition_list: List[
        BatchDefinition
    ] = test_runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=batch_request
    )

    assert batch_definition_list == expected_batch_definition_list

def test_get_batch_definition_list_from_batch_request_with_and_without_data_asset_name(
    basic_datasource,
):
    test_df: pd.DataFrame = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})

    batch_identifiers = {
        "airflow_run_id": 1234567890,
    }

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    # data_asset_name is missing
    batch_request: dict = {
        "datasource_name": basic_datasource.name,
        "data_connector_name": test_runtime_data_connector.name,
        "runtime_parameters": {
            "batch_data": test_df,
        },
        "batch_identifiers": batch_identifiers,
    }
    with pytest.raises(TypeError):
        # noinspection PyUnusedLocal
        batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    # test that name can be set as "my_data_asset"
    batch_request: dict = {
        "datasource_name": basic_datasource.name,
        "data_connector_name": test_runtime_data_connector.name,
        "data_asset_name": "my_data_asset",
        "runtime_parameters": {
            "batch_data": test_df,
        },
        "batch_identifiers": batch_identifiers,
    }
    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)
    batch_definition_list: List[
        BatchDefinition
    ] = test_runtime_data_connector.get_batch_definition_list_from_batch_request(
        batch_request=batch_request
    )
    assert len(batch_definition_list) == 1
    # check that default value has been set
    assert batch_definition_list[0]["data_asset_name"] == "my_data_asset"

def test__get_data_reference_list(basic_datasource):
    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    expected_data_reference_list: List[str] = []

    # noinspection PyProtectedMember
    data_reference_list: List[
        str
    ] = test_runtime_data_connector._get_data_reference_list()

    assert data_reference_list == expected_data_reference_list

def test_refresh_data_references_cache(basic_datasource):
    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )
    assert len(test_runtime_data_connector._data_references_cache) == 0

def test__generate_batch_spec_parameters_from_batch_definition(
    basic_datasource,
):
    batch_identifiers = {
        "custom_key_0": "staging",
        "airflow_run_id": 1234567890,
    }

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    expected_batch_spec_parameters: dict = {"data_asset_name": "my_data_asset"}

    # noinspection PyProtectedMember
    batch_spec_parameters: dict = test_runtime_data_connector._generate_batch_spec_parameters_from_batch_definition(
        batch_definition=BatchDefinition(
            datasource_name="my_datasource",
            data_connector_name="test_runtime_data_connector",
            data_asset_name="my_data_asset",
            batch_identifiers=IDDict(batch_identifiers),
        )
    )

    assert batch_spec_parameters == expected_batch_spec_parameters

def test__build_batch_spec(basic_datasource):
    batch_identifiers = {
        "custom_key_0": "staging",
        "airflow_run_id": 1234567890,
    }

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    batch_definition = BatchDefinition(
        datasource_name="my_datasource",
        data_connector_name="test_runtime_data_connector",
        data_asset_name="my_data_asset",
        batch_identifiers=IDDict(batch_identifiers),
    )

    batch_spec: BatchSpec = test_runtime_data_connector.build_batch_spec(
        batch_definition=batch_definition,
        runtime_parameters={
            "batch_data": pd.DataFrame({"x": range(10)}),
        },
    )
    assert type(batch_spec) == RuntimeDataBatchSpec
    assert set(batch_spec.keys()) == {"batch_data", "data_asset_name"}
    assert batch_spec["batch_data"].shape == (10, 1)

    batch_spec: BatchSpec = test_runtime_data_connector.build_batch_spec(
        batch_definition=batch_definition,
        runtime_parameters={
            "query": "my_query",
        },
    )
    assert type(batch_spec) == RuntimeQueryBatchSpec

    batch_spec: BatchSpec = test_runtime_data_connector.build_batch_spec(
        batch_definition=batch_definition, runtime_parameters={"path": "my_path"}
    )
    assert type(batch_spec) == PathBatchSpec

    batch_spec: BatchSpec = test_runtime_data_connector.build_batch_spec(
        batch_definition=batch_definition,
        runtime_parameters={"path": "s3://my.s3.path"},
    )
    assert type(batch_spec) == S3BatchSpec

    batch_spec: BatchSpec = test_runtime_data_connector.build_batch_spec(
        batch_definition=batch_definition,
        runtime_parameters={"path": "s3a://my.s3.path"},
    )
    assert type(batch_spec) == S3BatchSpec

def test__get_data_reference_name(basic_datasource):
    data_connector_query: dict = {
        "batch_filter_parameters": {
            "airflow_run_id": 1234567890,
        }
    }
    batch_identifiers = IDDict(data_connector_query["batch_filter_parameters"])

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    assert (
        test_runtime_data_connector._get_data_reference_name(batch_identifiers)
        == "1234567890"
    )

    data_connector_query: dict = {
        "batch_filter_parameters": {
            "run_id_1": 1234567890,
            "run_id_2": 1111111111,
        }
    }
    batch_identifiers = IDDict(data_connector_query["batch_filter_parameters"])

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    assert (
        test_runtime_data_connector._get_data_reference_name(batch_identifiers)
        == "1234567890-1111111111"
    )

def test_batch_identifiers_datetime(
    basic_datasource,
):
    test_df: pd.DataFrame = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})

    batch_identifiers: dict

    batch_identifiers = {
        "pipeline_stage_name": "core_processing",
        "airflow_run_id": 1234567890,
        "custom_key_0": datetime.datetime.utcnow(),
    }

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    # Verify that all keys in batch_identifiers are acceptable as batch_identifiers
    batch_request: dict = {
        "datasource_name": basic_datasource.name,
        "data_connector_name": test_runtime_data_connector.name,
        "data_asset_name": "IN_MEMORY_DATA_ASSET",
        "runtime_parameters": {"batch_data": test_df},
        "batch_identifiers": batch_identifiers,
    }
    batch_request: RuntimeBatchRequest = RuntimeBatchRequest(**batch_request)

    batch_definition = (
        test_runtime_data_connector.get_batch_definition_list_from_batch_request(
            batch_request=batch_request
        )[0]
    )

    batch = Batch(
        data=test_df, batch_request=batch_request, batch_definition=batch_definition
    )

    try:
        _ = batch.id
    except TypeError:
        pytest.fail()

def test_temp_table_schema_name_included_in_batch_spec(basic_datasource):
    batch_identifiers = {
        "custom_key_0": "staging",
        "airflow_run_id": 1234567890,
    }

    test_runtime_data_connector: RuntimeDataConnector = (
        basic_datasource.data_connectors["test_runtime_data_connector"]
    )

    batch_definition = BatchDefinition(
        datasource_name="my_datasource",
        data_connector_name="test_runtime_data_connector",
        data_asset_name="my_data_asset",
        batch_identifiers=IDDict(batch_identifiers),
    )

    batch_spec: BatchSpec = test_runtime_data_connector.build_batch_spec(
        batch_definition=batch_definition,
        runtime_parameters={"query": "my_query", "temp_table_schema_name": "my_schema"},
    )
    assert type(batch_spec) == RuntimeQueryBatchSpec
    assert batch_spec["temp_table_schema_name"] == "my_schema"


text:
<component name="libraryTable">
  <library name="recyclerview-stickyheaders-0.5.2">
    <CLASSES>
      <root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.eowise/recyclerview-stickyheaders/0.5.2/res" />
      <root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.eowise/recyclerview-stickyheaders/0.5.2/jars/classes.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES>
      <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.eowise/recyclerview-stickyheaders/0.5.2/c9be8b049f9c99f1de72db2bb1c16cf8a6b3751e/recyclerview-stickyheaders-0.5.2-sources.jar!/" />
    </SOURCES>
  </library>
</component>


text:
package it.quartara.boser.action.handlers;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import javax.persistence.EntityManager;

import org.apache.solr.common.SolrDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import it.quartara.boser.action.ActionException;
import it.quartara.boser.model.IndexField;
import it.quartara.boser.model.Search;
import it.quartara.boser.model.SearchKey;
import it.quartara.boser.solr.SolrDocumentListWrapper;

/**
 * Scrive su file i risultati di ricerca.
 * Crea un file con il nome della chiave.
 * Il percorso del file viene letto da un Parameter con chiave SEARCH_REPO.
 *
 * @author webny
 *
 */
public class TxtResultWriterHandler extends AbstractActionHandler {

	private static final String TITLE = "RISULTATI DELLA RICERCA\r\n";

	private static final Logger log = LoggerFactory.getLogger(TxtResultWriterHandler.class);

	public TxtResultWriterHandler(EntityManager em, File searchRepo) {
		super(em, searchRepo);
	}

	@Override
	protected void execute(Search search, SearchKey key, SolrDocumentListWrapper documents) throws ActionException {
		File outputFile = new File(searchRepo.getAbsolutePath()+File.separator
									+"RES-"+getSearchResultFileNameSubstringByKey(key)
									+"-K"+key.getId()
									+".txt");
		try {
			PrintWriter writer = new PrintWriter(outputFile);
			writer.println(FILE_HEADER);
			writer.println(TITLE);
			writer.println(documents.getList().size()+" risultati per "+key.getQuery()+"\r\n");
			for (int i = 0; i < documents.getList().size(); i++) {
				SolrDocument doc = documents.getList().get(i);
				writer.println(i+1+")"+doc.getFieldValue(IndexField.URL.toString()));
				writer.println(doc.getFieldValue(IndexField.TITLE.toString())+"\r\n");
			}
			writer.close();
			log.info("wrote file: {}", outputFile.getAbsolutePath());
		} catch (IOException e) {
			String msg = "problema di scrittura file dei risultati";
			throw new ActionException(msg, e);
		}
	}

}


text:
<?xml version="1.0"?>
<configuration xmlns:xct="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add key="RemoveNewLine" xct:Transform="Remove" xct:Locator="Match(key)"/>
    <add key="RemoveExtraSpace1" xct:Transform="Remove" xct:Locator="Match(key)"/>
    <add key="InsertNewLine1" value="This tag was added" xct:Transform="InsertBefore(add[@key='InsertTarget1'])"/>
    <add key="InsertNewLine2" value="This tag was added" xct:Transform="InsertAfter(add[@key='InsertTarget1'])"/>
    <add key="LookAheadInserted" value="This tag was added" xct:Transform="InsertBefore(add[@key='LookAheadTarget'])" />
  </appSettings>

  <appSettings xct:Transform="Insert">
    <!-- This appSettings section should be added to the end
         of the document, and all child elements including the
         comment should be indented according to local formatting
         in the source document -->

    <add key="NewChild1" value="This is the first new child element"/><add key="NewChild2" value="This is the second new child element"/>
  </appSettings>

  <location>
    <appSettings xct:Locator="Condition(1)">
      <add key="NewChild3" value="New node in empty tag" xct:Transform="Insert"/>
    </appSettings>

    <appSettings xct:Locator="Condition(2)">
      <add key="NewChild4" value="New node between start and end tags" xct:Transform="Insert"/>
    </appSettings>

    <appSettings xct:Locator="Condition(3)">
      <add key="NewChild5" value="New node between start and end tags" xct:Transform="Insert"/>
    </appSettings>
  </location>

  <location path="somepath" xct:Locator="XPath(/configuration/backward/tag/indenting/structure)" xct:Transform="Insert">
    <appSettings>
      <add key="SomePathSetting" value="Just a test of deep nesting"/>
    </appSettings>
  </location>

  <list>
    <item>
      <property xct:Transform="InsertMultiple"/>
    </item>
  </list>

  <list2>
    <item xct:Locator="Condition(.='Zero')" xct:Transform="ReplaceAll">0</item>
  </list2>
</configuration>


text:
<!DOCTYPE html>
<title>RegexMatcher.js Testing</title>
<link rel="stylesheet" href="qunit/qunit.css">


text:
const expect = require('expect')
const CleanServer = require('../src/lib/CleanMock')

describe('Test Clean Mock', () => {
  it('should resolve requests with Clean', function (done) {
    let mockTest = new Promise((resolve, reject) => {
      let mock = new CleanServer()
      mock.clean()
      resolve(true)
    })
    mockTest
            .then(() => {
              setTimeout(() => {
                done()
              }, 1000)
            })
  })
})


text:
```
npm install
npm start
open http://localhost:3000
```


text:
package com.hazelcast.client.impl.protocol.codec;

import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.Generated;
import com.hazelcast.client.impl.protocol.codec.builtin.*;
import com.hazelcast.client.impl.protocol.codec.custom.*;

import javax.annotation.Nullable;

import static com.hazelcast.client.impl.protocol.ClientMessage.*;
import static com.hazelcast.client.impl.protocol.codec.builtin.FixedSizeTypesCodec.*;

/*
 * This file is auto-generated by the Hazelcast Client Protocol Code Generator.
 * To change this file, edit the templates or the protocol
 * definitions on the https://github.com/hazelcast/hazelcast-client-protocol
 * and regenerate it.
 */

/**
 * Deploys the list of classes to cluster
 * Each item is a Map.Entry<String, byte[]> in the list.
 * key of entry is full class name, and byte[] is the class definition.
 */
@Generated("f8c8ce291fb75fb37a8f859816f7a1e8")
public final class ClientDeployClassesCodec {
    //hex: 0x000D00
    public static final int REQUEST_MESSAGE_TYPE = 3328;
    //hex: 0x000D01
    public static final int RESPONSE_MESSAGE_TYPE = 3329;
    private static final int REQUEST_INITIAL_FRAME_SIZE = PARTITION_ID_FIELD_OFFSET + INT_SIZE_IN_BYTES;
    private static final int RESPONSE_INITIAL_FRAME_SIZE = RESPONSE_BACKUP_ACKS_FIELD_OFFSET + BYTE_SIZE_IN_BYTES;

    private ClientDeployClassesCodec() {
    }

    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"})
    public static class RequestParameters {

        /**
         * list of class definitions
         */
        public java.util.List<java.util.Map.Entry<java.lang.String, byte[]>> classDefinitions;
    }

    public static ClientMessage encodeRequest(java.util.Collection<java.util.Map.Entry<java.lang.String, byte[]>> classDefinitions) {
        ClientMessage clientMessage = ClientMessage.createForEncode();
        clientMessage.setRetryable(false);
        clientMessage.setOperationName("Client.DeployClasses");
        ClientMessage.Frame initialFrame = new ClientMessage.Frame(new byte[REQUEST_INITIAL_FRAME_SIZE], UNFRAGMENTED_MESSAGE);
        encodeInt(initialFrame.content, TYPE_FIELD_OFFSET, REQUEST_MESSAGE_TYPE);
        encodeInt(initialFrame.content, PARTITION_ID_FIELD_OFFSET, -1);
        clientMessage.add(initialFrame);
        EntryListCodec.encode(clientMessage, classDefinitions, StringCodec::encode, ByteArrayCodec::encode);
        return clientMessage;
    }

    public static ClientDeployClassesCodec.RequestParameters decodeRequest(ClientMessage clientMessage) {
        ClientMessage.ForwardFrameIterator iterator = clientMessage.frameIterator();
        RequestParameters request = new RequestParameters();
        //empty initial frame
        iterator.next();
        request.classDefinitions = EntryListCodec.decode(iterator, StringCodec::decode, ByteArrayCodec::decode);
        return request;
    }

    @edu.umd.cs.findbugs.annotations.SuppressFBWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"})
    public static class ResponseParameters {
    }

    public static ClientMessage encodeResponse() {
        ClientMessage clientMessage = ClientMessage.createForEncode();
        ClientMessage.Frame initialFrame = new ClientMessage.Frame(new byte[RESPONSE_INITIAL_FRAME_SIZE], UNFRAGMENTED_MESSAGE);
        encodeInt(initialFrame.content, TYPE_FIELD_OFFSET, RESPONSE_MESSAGE_TYPE);
        clientMessage.add(initialFrame);

        return clientMessage;
    }

    public static ClientDeployClassesCodec.ResponseParameters decodeResponse(ClientMessage clientMessage) {
        ClientMessage.ForwardFrameIterator iterator = clientMessage.frameIterator();
        ResponseParameters response = new ResponseParameters();
        //empty initial frame
        iterator.next();
        return response;
    }

}


text:
extern "C" {
    #[link_name = "_ZN7MyClass26example_check_no_collisionE"]
    pub static mut MyClass_example_check_no_collision:
        *const ::std::os::raw::c_int;
}


text:
package stressql

import (
	"bufio"
	"bytes"
	"io"
	"log"
	"os"
	"strings"

	"github.com/influxdata/influxdb/influxql"
	"github.com/influxdata/influxdb/stress/v2/statement"
	stressql "github.com/influxdata/influxdb/stress/v2/stressql/statement"
)

// Token represents a lexical token.
type Token int

// These are the lexical tokens used by the file parser
const (
	ILLEGAL Token = iota
	EOF
	STATEMENT
	BREAK
)

var eof = rune(0)

func check(e error) {
	if e != nil {
		log.Fatal(e)
	}
}

func isNewline(r rune) bool {
	return r == '\n'
}

// Scanner scans the file and tokenizes the raw text
type Scanner struct {
	r *bufio.Reader
}

// NewScanner returns a Scanner
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{r: bufio.NewReader(r)}
}

func (s *Scanner) read() rune {
	ch, _, err := s.r.ReadRune()
	if err != nil {
		return eof
	}
	return ch
}

func (s *Scanner) unread() { _ = s.r.UnreadRune() }

func (s *Scanner) peek() rune {
	ch := s.read()
	s.unread()
	return ch
}

// Scan moves the Scanner forward one character
func (s *Scanner) Scan() (tok Token, lit string) {
	ch := s.read()

	if isNewline(ch) {
		s.unread()
		return s.scanNewlines()
	} else if ch == eof {
		return EOF, ""
	} else {
		s.unread()
		return s.scanStatements()
	}
	// golint marks as unreachable code
	// return ILLEGAL, string(ch)
}

func (s *Scanner) scanNewlines() (tok Token, lit string) {
	var buf bytes.Buffer
	buf.WriteRune(s.read())

	for {
		if ch := s.read(); ch == eof {
			break
		} else if !isNewline(ch) {
			s.unread()
			break
		} else {
			buf.WriteRune(ch)
		}
	}

	return BREAK, buf.String()
}

func (s *Scanner) scanStatements() (tok Token, lit string) {
	var buf bytes.Buffer
	buf.WriteRune(s.read())

	for {
		if ch := s.read(); ch == eof {
			break
		} else if isNewline(ch) && isNewline(s.peek()) {
			s.unread()
			break
		} else if isNewline(ch) {
			s.unread()
			buf.WriteRune(ch)
		} else {
			buf.WriteRune(ch)
		}
	}

	return STATEMENT, buf.String()
}

// ParseStatements takes a configFile and returns a slice of Statements
func ParseStatements(file string) ([]statement.Statement, error) {
	seq := []statement.Statement{}

	f, err := os.Open(file)
	check(err)

	s := NewScanner(f)

	for {
		t, l := s.Scan()

		if t == EOF {
			break
		}
		_, err := influxql.ParseStatement(l)
		if err == nil {

			seq = append(seq, &statement.InfluxqlStatement{Query: l, StatementID: stressql.RandStr(10)})
		} else if t == BREAK {
			continue
		} else {
			f := strings.NewReader(l)
			p := stressql.NewParser(f)
			s, err := p.Parse()
			if err != nil {
				return nil, err
			}
			seq = append(seq, s)

		}
	}

	f.Close()

	return seq, nil

}


text:
<?php

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
    'name' => 'lemans',
//    "defaultController" => "web/welcome",
    // preloading 'log' component
    'preload' => array('log'),
    // autoloading model and component classes
    'import' => array(
        'application.models.*',
        'application.components.*',
    ),
    'modules' => array(
    // uncomment the following to enable the Gii tool
    /*
      'gii'=>array(
      'class'=>'system.gii.GiiModule',
      'password'=>'Enter Your Password Here',
      // If removed, Gii defaults to localhost only. Edit carefully to taste.
      'ipFilters'=>array('127.0.0.1','::1'),
      ),
     */
    ),
    // application components
    'components' => array(
        "twitter" => array(
            "class" => "ext.yii-twitter-OAuth.STwitter",
            "consumer_key" => "UOPfUKiyPwdRX3CBP3fWK61XE",
            "consumer_secret" => "wTu5hYsRkVnWwLnBDjTdLHI5xlmMbQW77NccxvwtIKEQuubSSw",
            "callback" => "http://lemans.local/api/weibo/twittercallback",
            "signinParams" => array("force_write"),
        ),
        'user' => array(
            // enable cookie-based authentication
            'allowAutoLogin' => true,
        ),
        // uncomment the following to enable URLs in path-format
        'urlManager' => array(
            'urlFormat' => 'path',
            'rules' => array(
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            ),
        ),
        // uncomment the following to use a MySQL database
        'db' => array(
            'connectionString' => 'mysql:host=localhost;dbname=lemans',
            'emulatePrepare' => true,
            'username' => 'root',
            'password' => 'admin',
            'charset' => 'utf8',
        ),
        'errorHandler' => array(
            // use 'site/error' action to display errors
            'errorAction' => 'web/error',
        ),
        "session" => array(
            "autoStart" => true,
            "sessionName" => "lemans_sss",
            "cookieMode" => "only",
            "savePath" => dirname(__FILE__). '/../sessions',
        ),
        'log' => array(
            'class' => 'CLogRouter',
            'routes' => array(
                array(
                    'class' => 'CFileLogRoute',
                    'levels' => 'error, warning, trace',
                ),
            // uncomment the following to show log messages on web pages
            /*
              array(
              'class'=>'CWebLogRoute',
              ),
             */
            ),
        ),
    ),
    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
    'params' => array(
        // this is used in contact page
        'adminEmail' => 'jziwenchen@gmail.com',
        "weibo_uid" => "5072167230",
        'startTime'=>'2014-05-13 12:00:00',
    ),
);


text:
package com.facebook.react.uimanager;

import com.facebook.react.common.ClearableSynchronizedPool;
import com.facebook.yoga.YogaNode;

/** Static holder for a recycling pool of YogaNodes. */
public class YogaNodePool {

  private static final Object sInitLock = new Object();
  private static ClearableSynchronizedPool<YogaNode> sPool;

  public static ClearableSynchronizedPool<YogaNode> get() {
    if (sPool != null) {
      return sPool;
    }

    synchronized (sInitLock) {
      if (sPool == null) {
        sPool = new ClearableSynchronizedPool<>(1024);
      }
      return sPool;
    }
  }
}